The recent decades have witnessed refrigeration systems playing an important role in the life of human beings, with wide applications in various fields, including building comfort, food storage, food transportation and the medical special care units. However, if the temperature is not controlled well, it will lead to many harmful public health effects, such as the human being catching colds, food spoilage and harm to the recovering patients. Besides, refrigeration systems consume a significant portion of the whole society’s electricity usage, which consequently contributes a considerable amount of carbon emissions into the public environment. In order to protect human health and improve the energy efficiency, an optimal control strategy is designed in this paper with the following steps: (1) identifying the refrigeration system model based on a least squares method; (2) tuning an initial group of parameters of the proportional-integral-derivative (PID) controller via the pidTuner Toolbox of Matlab; (3) using an intelligent algorithm, namely fruit fly optimization (FOA), to further optimize the parameters of the PID controller. By comparing the optimal PID controller and the controller provided in the reference, the simulation results demonstrate that the proposed optimal PID controller can produce a more controllable temperature, with less tacking overshoot, less settling time, and more stable performance under a constant set-point.