Photoelectron spectroscopy of localized levels near surfaces: Scattering effects and relaxation shifts