Optimizing LCOE instead of TCO

Hello everyone,

At work I’m using an in-house MIP optimization tool for techno-economic optmization of complex energy systems.
The tool always minimizes the discounted Total Cost of Ownership (TCO) (CAPEX + OPEX - Revenues - salvage values) while meeting a given energy demand profile. This works perfectly fine for most applications.
If I have a fixed energy demand, minimizing the TCO always equates to minimizing the Levelized cost of Electricity (LCoE).

But what can I do if I want to allow for a variable energy production and optimize the LCoE?
A possible application: grid-connected PV + Battery, with restrictions on feed-in at certain hours.
→ Adding battery capacity allows for higher production, but may disproportionately increase the TCO, leading to higher LCoE.

How would you approach this?