Theory of inelastic scattering from quantum impurities