We estimate the galaxy stellar mass function and stellar mass density for star-forming and quiescent galaxies with 0.210^10.7Msun. For the mass function of the quiescent galaxies, we do not find any significant evolution of the high-mass end at z<1; however we observe a clear flattening of the faint-end slope. From z~3 to z~1, the density of quiescent galaxies increases over the entire mass range. Their comoving stellar mass density increases by 1.6 dex between z~3 and z~1 and by less than 0.2dex at z<1. We infer the star formation history from the mass density evolution and we find an excellent agreement with instantaneous star formation rate measurements at z<1.5, while we find differences of 0.2dex at z>1.5 consistent with the expected uncertainties. We also develop a new method to infer the specific star formation rate from the mass function of star-forming galaxies. We find that the specific star formation rate of 10^10Msun galaxies increases continuously in the redshift range 1