Policies reasoned by global climate change and increasing commodity prices due to the international energy crisis force district heating providers to transform their assets. Pit thermal energy storage combined with solar energy can improve this transformation process. Optimal energy planning of district heating systems is often achieved by applying a linear programming model due to its fast computing. Unfortunately, depicting those systems in linear programming requires complexity reduction. We introduce a method capable of designing and operating the system with the complexity increase of considering the top and bottom temperatures of the pit thermal energy storage in linear programming. Firstly, we extract and clean data from existing sites and simulations of seasonal storages. Secondly, we develop a polynomial regression model based on the extracted data to predict the top and bottom temperatures. Lastly, we develop a mixed-integer linear programming model using the predictions and compare it to existing sites. The model uses solar thermal energy, a pit thermal energy storage, and other units to meet the demand of a district heating system. The polynomial regression results show an accuracy of up to 92 % with only a few features to base the prediction. The optimization model can design the storage and depict the correlation between decreasing specific costs and thermal losses due to an increasing volume. The control strategy of the heat pump requires further improvement.