A standard solution uses an all-digital PLL with the grid voltage as reference, comprised of ADC, multiplier phase detector, PI loop filter, NCO with sine table. To generate the sine pwm, the NCO signal has to be multiplied with a factor to adjust the output to the actual grid voltage, usually driven by a current/power control loop.
Fitting the solution to a PIC18 is an ambitious project. There are probably simpler solutions using the sampled and filtered grid voltage as pwm reference, or a simplified PLL synchronizing to the grid voltage zero crossing.