Reducing the waste of building energy is important for the development of green environment. In this paper, based on the dynamic calculation method of various types of cold loads in the building temperature field, a four-wire platinum RTD sensor is selected as the physical device for real-time monitoring of space temperature to improve the credibility of temperature collection. The inverse distance weight model based on local parameter optimization is constructed, combined with particle swarm optimization algorithm and K-dimensional tree, etc., to realize temperature field prediction and energy consumption optimization. The constructed model is applied to the temperature prediction simulation and energy saving optimization practice of large buildings to judge the practical value of the model. The results show that the data collection error is minimized when the search height distance is 2 and the weight coefficient is 2.5-3. In the comparison between the model simulation prediction value and the measured temperature value, the average value of temperature difference in the horizontal and vertical directions is 0.250℃ and 0.162℃ respectively, which is a small error. In 10 energy consumption optimization experiments, this paper’s model is able to achieve the optimization of building energy consumption of 0.08-0.80kWh/m². Using the model of this paper can carry out high-precision prediction and energy consumption optimization of building energy-saving design.