This paper presents a trigeneration facility based on a biogas driven gas turbine cycle for electricity production and an air to water heat pump for simultaneous extraction of cooling and potable water, and evaluates its robustness and effectiveness under different climatic conditions and variable demands. The air to water heat pump, which consists of an inside evaporator fan, expansion device, condenser, evaporator, and a compressor, is installed for supplying the cooling load of a hospital building in summer. In the refrigeration cycle, R134a absorbs heat from the inside warm air for space cooling and releases it to the saline water for driving a desalination process. Maximum values of cooling and electrical demands of a standard hospital building, where is located in south of Iran, over the hottest day of 2018 are considered for the worst case implementation. Engineering equation solver and general algebraic mathematical modeling system are employed to develop the non-linear optimization strategy, find the best operating point of the air to water heat pump based trigeneration plant, and minimize its energy cost under the greatest load level. Moreover, the sensitivity of the gained output ratio of desalination cycle to the relative humidity of the air entering and leaving the humidifier, the dehumidifier and humidifier effectiveness, and the top and bottom temperatures are comprehensively analyzed. The relative humidity of air entering the humidifier and the larger dehumidifier effectiveness have the significant effects on increasing the gained output ratio of the desalination cycle. Due to intense solar irradiation in summer, the seawater temperature naturally increases, which results in larger gained output ratio and higher mass flow rate of pure water.