There is large annual discharge of sewage in cities, in which a large amount of sludge and suspended substance exists. After being treated in the sewage disposal plant, the sewage produces a large amount of sludge, which pollutes the environment. In fact, the sludge could be useful, and it is rewarding to study how to turn it into resource. This paper provides one way to utilize the sludge. Ferment of sludge produces biogas, which is sent to the gas engine to make the heat pump system operate, providing heating and cooling for buildings. This system consists of two parts: the gas engine system and the heat pump system. The sludge is fermented to produce combustible gas. The gas enters the engine system, and bums inside the gas engine, driving the engine to rotate. The engine is coaxially connected with the shaft of the compressor. And the whole system provides heating or cooling for buildings, saving electronic energy. Besides the introduction of the system, energy efficiencies of this system when several different working fluids are used are alson analyzed.