Cogeneration or combined heat and power (CHP) energy system could concurrently produce electrical and heat energies. Nonetheless, its integration in energy planning would need to consider interactions with other energy carriers, energy storages, and transmission networks. Previous works have used energy hub (EH) modelling to optimise the energy flow in a CHP energy system with predetermined energy components. In this paper, an Optimal Cogeneration Model (OCM) is proposed to consider the EH design which (1) enables the flexible selection between different energy transformation technologies, then (2) minimises the cost and environmental emission constraints concerning the technical characteristics and operating conditions of the selected EH components. Mixed-integer linear programming (MILP) has been used to model the optimisation problem in GAMS software. Based on the case study, an EH with CHP and energy storage system (ESS) has been developed with the minimised total annual cost (TAC) of 27.02 x 106 MYR/y for a pharmaceutical facility. The research output - the developed OCM serves as an integrated analysis tool for potential cogenerators to plan and determine the economic feasibility of CHP implementation.