Can thunderstorms be thought of as a heat engine?
Yes, they can.

Broadly speaking, most dynamical atmospheric phenomena are heat engines in one form or another. Ultimately the heat source is due to sunlight heating up the ground, and the cold sink is the upper atmosphere, which stays cold due to emitting thermal radiation into space. Large convection cells (such as tropical cyclones or the Hadley cells) act broadly like Carnot engines, adiabatically expanding packets of air as they're brought upwards from the ground to the upper atmosphere, then isothermally compressing them as they radiate into space, then adiabatically compressing them as they travel back down to the surface, and then isothermally expanding them as they pick up heat from the ground. (This description is a very rough approximation to the reality.) The net effect is to transfer heat from the ground to the upper atmosphere, while converting a small amount of that heat into kinetic energy, which keeps the whole thing moving.

Thunderstorms are quite an interesting case, because they are driven by latent heat as well as sensible heat. The air near the surface is not just warm but moist, due to evaporation and evapotranspiration from plants. As air rises it cools. Cool air can hold less moisture than warm air, so this can lead to condensation (i.e. the formation of clouds and rain). This condensation releases heat. A thunderstorm happens when condensation releases so much heat that the air starts to rise even faster, pulling more air up behind it. The moisture in this air then condenses, releasing more heat and pulling more air up, and so on. This is why thunderstorms often rise to a much greater height than the surrounding clouds.

Condensation releases heat, but evaporation uses up heat, which is why you feel cooler when you sweat. When water evaporates it takes heat away from the surface. That heat was put there by sunlight, and it gets released back again at the top of the thunderstorm. So a thunderstorm is part of a large-scale heat transport process that begins with evaporative cooling at the Earth's surface, and ends with the heat from condensation being transported into the upper atmosphere and ultimately radiated away into space.