Selling electricity back to provider
The power company have to install (or approve the installation of) a special meter (to monitor incoming and outgoing power) and a grid-tie inverter. It's not something you can just start doing by yourself.

Usually, in locations where these arrangements are permitted or encouraged, it's done under a regional government scheme, where you get some form of incentive for installing the kit, and the power company is obliged to buy your power at a premium price, whether they want it at that moment or not. It often happens that you are paid a price per unit you generate, whether you use it, or whether it gets supplied back onto the grid.

The grid-tie inverter simply pushes current into the constant voltage of the grid, just the opposite of you pulling current out of the grid's constant voltage when you use power. That way, there's no short circuit.