A significant increase in the use of solar energy can be observed. Solar energy is not, however, widely used in Latvia. The aim of this paper is to devise an algorithm to evaluate the possibility of integrating solar energy into the district heating system (DHS) of Latvia for both space heating and the supply of domestic hot water. The methodology was tested on a district heating system in a municipality in Latvia with 20,000 inhabitants. The existing DHS operation data were processed for the analysis and optimization of the system. Optimization of the system includes energy efficiency measures (EEM). Results show the possible energy production from solar energy depends on the area of different solar collector fields and thermal water storage tank volumes, as well as the probable costs of the system. It would be necessary to install solar collection fields of 9,000 m2 to 72,900 m2 with a properly sized TES in order to produce from 6,000 MWh/year up to 23,700 MWh/year. With this system it would be possible to supply 10 % to 78% of the total heat demand with solar energy in any given DHS. If EEM have also been implemented, solar energy share can be increased.