The first stage produces a regulated DC bus, perhaps just above the peak voltage of the AC grid supply. This DC bus is the input for the AC inverter, which might uses a H bridge and PWM at high frequency and inductors or a filter to remove the high frequency PWM component, and produce a suitable 50/60Hz sine wave that tracks the grid voltage/frequency. This injects sine wave current into the grid. There is usually a transformer (high frequency) somewhere in the system for DC/galvanic isolation between the source and the load, removing confusion over grounding. This is especially so because the DC supply may be bipolar - center tapped DC. The DC bus voltage can be controlled to achieve the desired load current, for example for maximum power point control.
Consider it is the same situation as a paralleled AC generator. There must be synchronised phase, and voltage control to determine the current flow. The control is often made by a micro-controller which samples the grid voltage and generates appropriate PWM, and controls the DC bus. It usually needs to measure voltage and current (and work out power) at various key points, and may use zero crossings of the grid waveform to drive the inverter using a sine look up table.
There is likely to be a safety control that disables the output (by shutting down the DC bus, with crowbar of the DC bus usually), if the grid becomes disconnected. This is to prevent energising the grid locally by back-feed or 'islanding effects' where small parts of the grid are isolated and driven by the grid tie system.
The first link shows the basics, and has links to other references.