If the comparison is between a 9mm and .40 S&W individual cartridge from comparable barrel lengths, the .40 has the edge as far as energy goes.
From Speer's website, for example, the 124gr Gold Dot is listed as having a muzzle velocity of 1150 FPS from a 4" barrel, yielding 364 ft-lbs of energy at the muzzle.
The same site has the 165gr Gold Dot as having the same muzzle velocity despite the larger/heavier projectile and having 484 ft-lbs of energy at the muzzle.
Sure, there is the option of +P with the 9mm. There's also the option of using a lighter bullet with the .40 S&W. For example, the 124gr +P 9mm Gold Dot is listed as having a velocity (and energy) of 1220 FPS (410 ft-lbs), while the still heavier 155gr .40 S&W Gold Dot is listed as having 1200 FPS (496 ft-lbs).
There are few if any out there who will argue that the 9mm is the more powerful cartridge of the two, because the opposite is true. However, the real question is whether the increased recoil and decreased magazine capacity justifies any advantage the additional "power" offers.
Obviously if I somehow were to know I had only one shot and it would hit somewhere in center mass, I would choose something in .40 S&W. Just as obvious is that reality doesn't work this way and other factors often take the lead in making a decision.
My CCW carry pistols are a Kahr K9 and a Bersa UC9, so you probably already know what I think. But in all fairness, I do carry a Steyr M40 while hiking because I actually do appreciate that extra punch when trekking through the land of black bears and mountain lions.