A method for first-principles calculations of spectra of strongly correlated systems is proposed. The impurity-Anderson-model is solved with a many-electron trial wave function. The obtained eigenvalues and eigenfunctions are used for one-electron removal (or addition) Greens-functions calculations. All parameters of the many-electron Hamiltonian are taken from band-structure calculations in the local density approximation with an on-site d-d Coulomb interaction (LDA+U). The method is applied to NiO and shows good agreement with experimental photoemission spectra and with the oxygen K x-ray-emission spectrum. Using MgO as an example, we show that the O K spectrum is equivalent to the oxygen partial density of states, and that there are no observable core-hole effects.