Combined heat and power (CHP) generation plants are an assessed valuable solution to significantly reduce primary energy consumption and carbon dioxide emissions. Nevertheless, the primary energy saving (PES) and CO2 reduction potentials of this solution are strictly related to the accurate definition and management of thermal and electric loads. Data-driven analysis could represent a significant contribution for optimizing the CHP plant design and operation and then to fully deploy this potential. In this paper, the use of a bi-level optimization approach for the design of a CHP is applied to a real application (a large Italian hospital in Rome). Based on historical data of the hospital thermal and electric demand, clustering analysis is applied to identify a limited number of load patterns representative of the annual load. These selected patterns are then used as input data in the design procedure. A Mixed Integer Linear Programming coupled with a Genetic Algorithm is implemented to optimize the energy dispatch and size of the CHP plant, respectively, with the aim of maximizing the PES while minimizing total costs and carbon emissions. Finally, the effects of integrating biogas from the Anaerobic Digestion (AD) of the Spent Coffee Ground (SCG) and Energy Storage (ES) technologies are investigated. The results achieved provide a benchmark for the application of these technologies in this specific field, highlighting performances and benefits with respect to traditional approaches. The effective design of the CHP unit allows for achieving CO2 reduction in the order of 10%, ensuring economic savings (up to 40%), when compared with a baseline configuration where no CHP is installed. Further environmental benefits can be achieved by means of the integration of AD and ES pushing the CO2 savings up to 20%, still keeping the economical convenience of the capital investment.