This question involves two cases: electrons bound to a nucleus and free electrons.
Bound electrons
Let's consider the hydrogen atom for simplicity. As far as I know, to be able to excite the electron, the energy of the photon should be in discrete values corresponding to the difference between energy levels inside the hydrogen atom. By the way in this link, the answer states that it is not the electrons that absorbs the photon but the atom in general, which makes sense to me (please correct or clarify if wrong).
The question is how long does the electron stay in that excited state, i.e. how quickly is the photon emitted back? Is it the same for all energy levels and all conditions like particle density (when many atoms together), temperature, presence of electric field, nucleus structure (neutron count) etc?
Free electrons
Again, according to the same link, free electrons do not absorb photons, which means they only undergo Compton scattering. Is this correct? If not, how long does it take for the photon be emitted back? Is the energy gain permanent?