Abstract Hellenic Aspropyrgos Refinery (HAR) is a state-owned petroleum refinery with a capacity of 130,000 barrels per day. The electric and part of the thermal loads of HAR are covered by a combined-cycle cogeneration plant of 54 MWe capacity, which is interconnected with the utility grid. The plant consists of two gas-turbine generators, two exhaust-gas boilers, four fuel-oil boilers and one steam-turbine generator. Steam is produced at four levels; high, medium, low and very low pressure. Low-sulphur fuel oil is burned in the boilers, while the gas turbines can operate in any one or in a combination of (a) diesel oil, (b) process-generated fuel gas. (c) a mixture of propane and propylene (LPG). Connection to the utility network allows for importing additional electricity, if there is need, or for exporting excess electricity. Due to the variety of sources which can be used to cover the loads, the interdependency between sources and the variation of technical and economic conditions with time, questions such as the following arise. Given the technical (e.g. needs in electricity and heat), environmental and economic conditions at any instant of time, what source and at what load should be used? Which is the quantity of electricity bought from or sold to the utility grid? In order to answer these questions, an optimization procedure has been developed which is supported by a thermoeconomic analysis of the system and modelling of the performance of the main components. The minimization of the operation expenses has been selected as the objective function. A computer program has been developed for the numerical solution of the optimization problem. In the present work, the optimization procedure and the computer program are described, numerical results are presented which show the importance of applying such a procedure to real-world complex systems, a sensitivity analysis with respect to important parameters is performed and conclusions are drawn regarding the usefulness and further improvements of the program.