Many production processes work with on-site Combined Heat and Power (CHP) systems to reduce their operational cost and improve their incomes by selling electricity to the external grid. Optimal management of these plants is key in order to take full advantage of the possibilities offered by the different electricity purchase or selling options. Traditionally, this problem is not considered for small cogeneration systems whose electricity generation cannot be decided independently from the main process production rate. In this work, a non-linear gray-box model is proposed in order to deal with this dynamic optimization problem in a simulated sugar factory. The validation shows that with only 52 equations, the whole system behavior is represented correctly and, due to its structure and small size, it can be adapted to any other production process working along a CHP with the same plant configuration.