We address the problem of finding the optimal lockdown and reopening policy during a pandemic like COVID-19, for a social planner who prioritizes health over short-term wealth accumulation. Agents are connected through a fuzzy network of contacts, and the planner’s objective is to determine the policy that contains the spread of infection below a tolerable incidence level, and that maximizes the present discounted value of real income, in that order of priority. We show theoretically that the planner’s problem has a unique solution. The optimal policy depends both on the configuration of the contact network and the tolerated infection incidence. Using simulations, we apply these theoretical findings to: (i) quantify the tradeoff between the economic cost of the pandemic and the infection incidence allowed by the social planner, and show how this tradeoff depends on network configuration; (ii) understand the correlation between different measures of network centrality and individual lockdown probability, and derive implications for the optimal design of surveys on social distancing behavior and network structure; and (iii) analyze how segregation induces differential health and economic dynamics in minority and majority populations, also illustrating the crucial role of patient zero in these dynamics.