Extended Hartree-Fock theory for excited states