All perfect praise be to Allah, The Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad, sallallahu ‘alayhi wa sallam, is His slave and Messenger.
There is no religious impediment to investing in what may be used for both lawful and unlawful purposes, such as energy. The probability that some sinners may benefit of it or that it may be used for an unlawful purpose does not forbid investing in it as long as it is mostly used for lawful purposes. For example, the Islamic Shariah does not prohibit growing grapes although some people use them to make wine, and so on. The scholars of Usool Al-Fiqh (the Fundamentals of Islamic Jurisprudence) refer to such matters as Masaalih Mulghaah (discredited public interests; i.e. public interests which have been nullified either explicitly or by indication in the Shariah).
At-Toofi wrote:
"As for the Maslahah Mulghaah such as forbidding the cultivation of grapes or the sharing of accommodation, in these situations, the Maslahah (public interest) is in conflict with the Mafsadah (public evil). However, the interest in these examples (forbidding the cultivation of grapes or the sharing of accommodation) is insignificant and the evil is significant. Therefore, discrediting such interests is the preponderant choice because they entail preventing the ascertained interest gained from growing grapes and from sharing a common accommodation due to a presumed evil, namely making wine or committing adultery. Even if the evil in these examples is assumed but not decisively ascertained while the conflicting interest is decisively ascertained, then the realization of the ascertained interest through tolerating the presumed evil is given priority over doing the opposite. Moreover, the mentioned evil is limited (to some people) whereas the expected interest is public. Tolerating a limited evil in order to realize a broad public interest is given precedence over doing the opposite." [Sharh Mukhtasar Ar-Rawdhah]
The same applies to public interests realized through producing and generating energy; they should not be neglected for fear of the presumed evil that some sinners may benefit or because they may use it in committing a prohibited act.
Allah knows best.