We use cosmological hydrodynamic simulations to investigate how inflows, star formation, and outflows govern the the gaseous and metal content of galaxies. In our simulations, galaxy metallicities are established by a balance between inflows and outflows as governed by the mass outflow rate, implying that the mass-metallicity relation reflects how the outflow rate varies with stellar mass (M*). Gas content is set by a competition between inflow into and gas consumption within the ISM, the latter being governed by the SF law, while the former is impacted by both wind recycling and preventive feedback. Stochastic variations in the inflow rate move galaxies off the equilibrium M*-Z and Z*-fgas relations in a manner correlated with star formation rate, and the scatter is set by the timescale to re-equilibrate. The evolution of both relations from z=3-0 is slow, as individual galaxies tend to evolve mostly along the relations. Gas fractions at a given M* slowly decrease with time because the cosmic inflow rate diminishes faster than the consumption rate, while metallicities slowly increase as infalling gas becomes more enriched. Observations from z~3-0 are better matched by simulations employing momentum-driven wind scalings rather than constant wind speeds, but all models predict too low gas fractions at low masses and too high metallicities at high M*. All our models reproduce observed second-parameter trends of the mass-metallicity relation with star formation rate and environment, indicating that these are a consequence of equilibrium and not feedback. Overall, the analytical framework of our equilibrium scenario broadly captures the relevant physics establishing the galaxy gas and metal content in simulations, which suggests that the cycle of baryonic inflows and outflows centrally governs the cosmic evolution of these properties in typical star-forming galaxies.