You are correct that most repeaters that are on buildings or typical towers get their energy from the commercial grid. The repeaters that I own are all commercially powered. Repeaters that are installed in remote locations almost always use solar panels with storage batteries as their energy source. I have talked with one repeater group that supplemented their solar energy with wind energy but they did it as an experiment and didn't feel it was practical at their location to use it as the sole energy source.
How much energy a repeater uses varies widely based upon the repeater construction, the amount of transmitter output power, and the duty cycle (idle vs. transmit) of the repeater. So we can put together a formula but many of the values vary according to the specifics of the repeater. I will use data from my repeaters to exemplify the formulas. The following examples and formulas are designed to be illustrative but not exhaustive.
Most solid state repeaters run off of a 12 volt bus. If the repeater is powered from a commercial mains supply, then a mains to 12 volt power supply is involved. This power supply has a conversion efficiency as it steps the mains supply down to 12 volts. Let's call this efficiency $k_1$. If the supply is a linear design, $k_1$ can typically range from 65% to 75%. If the supply is a switching supply, $k_1$ will typically range from 85% to 95%. My repeaters use a linear supply that is about 70% efficient.
Because a repeater must be always listening for a signal, the receiver of the repeater must always be powered on. In the repeaters that I own, the receiver draws about 0.5 amps off of the 12 volt supply. We can then calculate the required receiver power as:
$$P_{rcvr}=EI/k_1=12*0.5/0.7=8.6 \text{ watts} \tag 1$$
The transmitter in the repeater is generally turned off until the repeater is transmitting. The power output of a repeater transmitter will be anywhere from 10 watts to 250 watts. Above 250 watts is generally not used because even with a duplexer, the receiver desense becomes problematic. My repeaters put out about 80 watts. Power amplifiers in the transmitter have an efficiency factor that we will call $k_2$. Most FM and digital repeaters use a class C amplifier that will be about 80% efficient.
Since the repeater is not transmitting all the time, we need to apply a duty cycle factor that we will call $k_3$. This factor should be a representative average over a 24 hour, 7 day cycle. For the purposes of this estimate, let's call this 10%. We can now calculate the average transmitter power as:
$$P_{xmtr}=\frac{P_{out}k_3}{k_1k_2}=\frac{80*0.1}{0.7*0.8}=14.3 \text{ watts} \tag 2$$
The repeater also has a controller in it that monitors all the subsystems, turns on the transmitter, identifies the repeater, etc. On my repeaters, this draws about 0.5 amps. We can calculate the power required as:
$$P_{cntl}=EI/k_1=12*0.5/0.7=8.6 \text{ watts} \tag 3$$
So if we add the three power terms from formulas 1, 2 and 3 together, we have an average power consumption of 31.5 watts.
In the USA, we buy electricity by the kilowatt hour. There are ~731 hours in the average month, so the monthly energy requirement is:
$$kW⋅h=P_{watts}h/1000=31.5*731/1000=23 \text{ kW⋅h} \tag 4$$
The average electric energy rate in the US is 0.1247 US dollars per kilowatt hour. Using that as a basis, this example repeater owner would pay 2.87 dollars per month for the energy. In the USA, this may not tell the full story as there is often a minimum monthly billing or a facility charge that can come into play. At one of my repeater locations, for example, the energy charge is only 0.06851 dollars per kWh but there is an additional monthly facility charge of 24 dollars.
In some installations, a cooling or heating system may also be required in order to keep the repeater within its allowable operating temperature range. It would not be unusual that this system would consume more energy than the repeater itself. As an example, a simple fan tray could in itself consume 80 watts which is 58 kWh per month.
Note that if the repeater is running off of solar, the repeater owner will likely spend more time optimizing the energy consumption of the repeater. It will also likely be designed to run directly off of the 13.8 volt battery bus so there is no linear or switching supply efficiency factor. However, there is a charge controller between the solar panels and the battery that will have a comparable efficiency factor that affects the sizing of the required solar panels.