How can an inverter transfer energy to the power network?
Grid-tied inverters do exactly what you're describing. Adding power to the grid is far from trivial, and isn't something that a few paragraphs of explanation can fully cover. People have spent decades on this sort of research.

The best way I've heard to describe the grid is 'infinite sink' and 'infinite source'.

An inverter carefully and accurately monitors the phase of the grid voltage and keeps itself in agreement, else the grid will try and push/pull far more current than the inverter can produce. (Mechanical generators have to be similarly synchronized else the grid will correct the generators, sometimes catastrophically)

It also must detect grid interruptions (islanding) and disconnect itself such that linesmen working on an isolated section of grid don't get electrocuted.