In order to function well, markets have to be correctly regulated. In particular, externalities must be accounted for. Energy markets fail to do that (CO2 emissions is a large externality) and are broken - I wager we wouldn't depend on fossil fuels for much longer if it weren't the case.