Generalized derivations with nilpotent, power-central, and invertible values in prime and semiprime rings