We investigate the mass-metallicity relations for the gaseous (MZRgas) and stellar components (MZRstar) of local star-forming galaxies based on a representative sample from SDSS DR12. The mass-weighted average stellar metallicities are systematically lower than the gas metallicities. This difference in metallicity increases toward galaxies with lower masses and reaches 0.4-0.8 dex at 109M⊙ (depending on the gas metallicity calibration). As a result, the MZRstar is much steeper than the MZRgas. The much lower metallicities in stars compared to the gas in low mass galaxies implies dramatic metallicity evolution with suppressed metal enrichment at early times. The aim of this paper is to explain the observed large difference in gas and stellar metallicity and to infer the origin of the mass-metallicity relations. To this end we develop a galactic chemical evolution model accounting for star formation, gas inflow and outflow. By combining the observed mass-metallicity relation for both gas and stellar components to constrain the models, we find that only two scenarios are able to reproduce the observations. Either strong metal outflow or a steep IMF slope at early epochs of galaxy evolution is needed. Based on these two scenarios, for the first time we successfully reproduce the observed MZRgas and MZRstar simultaneously, together with other independent observational constraints in the local universe. Our model also naturally reproduces the flattening of the MZRgas at the high mass end leaving the MZRstar intact, as seen in observational data.