We present a physically motivated model for the early coevolution of massive spheroidal galaxies and active nuclei at their centers. Within dark matter halos, forming at the rate predicted by the canonical hierarchical clustering scenario, the gas evolution is controlled by gravity, radiative cooling, and heating by feedback from supernovae and from the growing active nucleus. Supernova heating is increasingly effective with decreasing binding energy in slowing down the star formation and in driving gas outflows. The more massive protogalaxies virializing at earlier times are thus the sites of the faster star formation. The correspondingly higher radiation drag fastens the angular momentum loss by the gas, resulting in a larger accretion rate onto the central black hole. In turn, the kinetic energy carried by outflows driven by active nuclei can unbind the residual gas, thus halting both the star formation and the black hole growth, in a time again shorter for larger halos. For the most massive galaxies the gas unbinding time is short enough for the bulk of the star formation to be completed before Type Ia supernovae can substantially increase the Fe abundance of the interstellar medium, thus accounting for the -enhancement seen in the largest galaxies. The feedback from supernovae and from the active nucleus also determines the relationship between the black hole mass and the mass, or the velocity dispersion, of the host galaxy, as well as the black hole mass function. In both cases the model predictions are in excellent agreement with the observational data. Coupling the model with GRASIL (Silva et al. 1998), the code computing in a selfconsistent way the chemical and spectrophotometric evolution of galaxies over a very wide wavelength interval, we have obtained predictions in excellent agreement with observations for a number of observables that proved to be extremely challenging for all the current semianalytic models, including the submillimeter counts and the corresponding redshift distributions, and the epoch-dependent K-band luminosity function of spheroidal galaxies.