Emerging technologies and practices allow wastewater treatment facilities to recover valuable resources such as nutrients, energy, and recycled water during the wastewater treatment process. The ability to recover resources from wastewater introduces new tradeoffs in both water quality and quantity management. In particular, the fact that communities can obtain revenue from the sale of resources that are recovered from wastewater may help internalize the externalities of insufficient wastewater treatment. In this paper, we develop a theoretical model to characterize these tradeoffs within a hydroeconomic framework of optimal wastewater treatment with resource recovery, which is particularly well suited for applications in nutrient management. We use this model to derive analytical results that describe the economically optimal level of deployment, accounting for the fact that the technology or practice is costly and it generates benefits in the form of revenue from the recovered resource, as well as other societal benefits, such as improvements in human and ecosystem health. In addition, we present two examples using specific functional forms for treatment costs to demonstrate how the model can be applied to obtain general principles regarding societally optimal deployment. Our hydroeconomic framework can be used to explore the socioeconomic implications of strategies that target deployment of wastewater treatment with resource recovery, especially nutrients, at multiple scales.