Human societies are increasingly altering the water and biogeochemical cycles to both improve ecosystem productivity and reduce risks associated with the unpredictable variability of climatic drivers. These alterations, however, often cause large negative environmental consequences, raising the question as to how societies can ensure a sustainable use of natural resources for the future. Here we discuss how ecohydrological modeling may address these broad questions with special attention to agroecosystems. The challenges related to modeling the two-way interaction between society and environment are illustrated by means of a dynamical model in which soil and water quality supports the growth of human society but is also degraded by excessive pressure, leading to critical transitions and sustained societal growth-collapse cycles. We then focus on the coupled dynamics of soil water and solutes (nutrients or contaminants), emphasizing the modeling challenges, presented by the strong nonlinearities in the soil and plant system and the unpredictable hydroclimatic forcing, that need to be overcome to quantitatively analyze problems of soil water sustainability in both natural and agricultural ecosystems. We discuss applications of this framework to problems of irrigation, soil salinization, and fertilization and emphasize how optimal solutions for large-scale, long-term planning of soil and water resources in agroecosystems under uncertainty could be provided by methods from stochastic control, informed by physically and mathematically sound descriptions of ecohydrological and biogeochemical interactions.