Energy production doesn't have to be profitable, but no private investor would invest into a unprofitable business.
If energy production in Denmark would not by profitable, the Government of Denmark could nationalize the energy production, or push households to install more solar and sell the energy at predefined price to the grid, or increase taxes to pay out subsidies to make energy production profitable again for private investors. Or combine all this approaches.