What happens to excess energy fed into the power grid?
This is, as you might imagine, not something that has just one solution and the problem in itself is pretty complex as well. Let's break it down.

The power grid as it exists now in most civilized countries has a hierarchical structure: on top there are the large centralized power stations, beneath that are the large-scale MV distribution networks or distribution rings, then come the city grids (usually about 400kV) which are usually underground HV, neighborhood networks (20kV or multi-phase mains voltage) and then the low-voltage 'postal code' nets which distribute 115/230V. Of course, as your question already implies, this hierarchy presumes a net energy flow from power station to home, and not the other way around.

Most decentralized power generation - non-commercial solar panels, wind turbines and the like - happens at the house level, i.e. it produces 115/230VAC and pumps it into the mains supply. Most of the time this is fine because power generated is much less than power consumed and the net energy flow is still in the right direction. Rarely, but more often nowadays because of the low price of solar, the amount of power generated is more than the power consumed on the postal code level. For basically all power nets this is not that much of a problem actually. The transformers used to convert MV into 115/230V are just linear transformers and they work just as well in one direction as they work in the other. They almost never have PFC or other flow direction dependent parameters so it's fine.

The problem that most power grids are coping badly with, is what happens on one step above that. Here we arrive at the conversion step from the underground city grid to smaller blocks, and these transformer stations nowadays often have PFC or at least some kind of decoupling mechanism to make sure that interference from the city grid doesn't travel back to the HV power lines as it would through a linear transformer. If this unit generates more power than it consumes, that energy cannot (generally) go anywhere, or at least it is stopped from doing so by very expensive, not-that-easy-to-replace-everywhere electronics. The reflex response of the system is to throw a switch and separate this unit from the rest of the grid. Of course, this won't 'kill' this unit; the power generated will simply pump up the voltage on this grid up to the safety limit of power inverters (usually nominal voltage + 5-7%) and very often it will destabilize the AC frequency. But the power will continue to be there until a cloud passes, the grid drops below brownout voltages and the solar inverters all switch themselves off. This problem is called the island generation problem and is very hard to solve without some additional intelligence in the power grid and inverters (i.e. smart grids).

However, as you can see in this previous paragraph the extra energy doesn't necessarily go anywhere. If an island situation occurs, inverters are required not just to dump all their available energy on the grid, but to modulate themselves when the grid reaches a certain voltage. When that cloud eventually passes over, they will switch themselves off and the situation is resolved.

There are alternative protection mechanisms. Some countries have shorting switches that can be engaged with special (DTMF) signals over the power line. When an island is created, they can short out the power grid to ground and black out a section of the grid immediately. This however is not a very safe practice, as this often causes inductive spikes on the power grid which can damage both the grid and household electronics. Nowadays this is rarely used. It is however an important protection mechanism for power generators that don't regulate their output well and may cause an overvoltage situation.