With the decarbonisation of electricity generation, large scale heat pumps are becoming an increasingly viable prospect for district heating installations. Heat pumps couple heat demands to an intermittent electricity supply with varying electricity prices with the use of thermal energy storage providing flexibility to avoid peak electricity charges and minimise operating costs. However, the operating strategy for cost minimising in district heating system models is dependent on the size of heat pump and thermal energy storage capacity chosen and its operational conditions. Model predictive control techniques can be used to explore district heating configurations with varying forecast horizons. This study applies optimisation to a district heating operation model simulation to find low cost combinations of heat pump and thermal energy storage sizes.Physics-based representations of a district heating network and thermal energy storage are developed with ground source heat pumps and applied to a district heat load profile with hourly marginal electricity costs derived from a modelled zero-carbon electricity system as a basis for operation. Using a dynamic programming algorithm with different forecast horizons to minimise operational costs, the total costs of combinations of heat pump and thermal energy storage sizes are calculated.The operation at smaller thermal store sizes shows cycling multiple times per day, while at larger sizes these sub-daily cycles are maintained but longer multi-day cycles become more predominant. It was found that thermal energy storage equivalent of around 1% of annual demand is sufficient to minimise operating costs and enables flexibility beyond 4 days. This has important consequences for the electricity system and can facilitate the integration of variable renewable electricity.