We consider the contribution of nuclear polarization to the Lamb shift of K- and L-shell electrons in heavy atoms and quasiatoms. Our formal approach is based on the concept of effective photon propagators with nuclear-polarization insertions treating effects of nuclear polarization on the same footing as usual QED radiative corrections. We explicitly derive the modification of the photon propagator for various collective nuclear excitations and calculate the corresponding effective self-energy shift perturbatively. The energy shift of the 1s1/2 state in 92238U due to virtual excitation of nuclear rotational states is shown to be a considerable correction for atomic high-precision experiments. In contrast to this, nuclear-polarization effects are of minor importance for Lamb-shift studies in 82208Pb