  We study the effects of Active Galactic Nuclei (AGN) feedback on the
formation and evolution of galaxies in a semi-analytic model of galaxy
formation. This model is an improved version of the one described by Cora
(2006), which now considers the growth of black holes (BHs) as driven by (i)
gas accretion during merger-driven starbursts and mergers with other BHs, (ii)
accretion during starbursts triggered by disc instabilities, and (iii)
accretion of gas cooled from quasi-hydrostatic hot gas haloes. It is assumed
that feedback from AGN operates in the later case. The model has been
calibrated in order to reproduce observational correlations between BH mass and
mass, velocity dispersion, and absolute magnitudes of the galaxy bulge. AGN
feedback has a strong impact on reducing or even suppressing gas cooling, an
effect that becomes important at lower redshifts. This phenomenon helps to
reproduce the observed galaxy luminosity function (LF) in the optical and near
IR bands at z=0, and the cosmic star formation rate and stellar mass functions
over a wide redshift range (0<z<5). It also allows to have a population of
massive galaxies already in place at z>1, which are mostly early-type and have
older and redder stellar populations than lower mass galaxies, reproducing the
observed bimodality in the galaxy colour distribution, and the morphological
fractions. The evolution of the optical QSO LF is also reproduced, provided
that the presence of a significant fraction of obscured QSOs is assumed. We
explore the effects of AGN feedback during starbursts and new recent
prescriptions for dynamical friction time-scales. (ABRIDGED)
