Abstract In this paper we use stochastic polynomial optimization to derive high-performance operating strategies for heating networks with uncertain or variable demand. The heat flow in district heating networks can be regulated by varying the supply temperature, the mass flow rate, or both simultaneously, leading to different operating strategies. The task of choosing the set-points within each strategy that minimize the network losses for a range of demand conditions can be cast as a two-stage stochastic optimization problem with polynomial objective and polynomial constraints. We derive a generalized moment problem (GMP) equivalent to such a two-stage stochastic optimization problem, and describe a hierarchy of moment relaxations approximating the optimal solution of the GMP. Under various network design parameters, we use the method to compute (approximately) optimal strategies when one of, or both, the mass flow rate and supply temperature are varied for a benchmark heat network. We report that the performance of an optimally-parameterized fixed-temperature variable-mass-flow strategy can approach that of a fully variable strategy.