Control system to minimize a parameter
The microcontroller is the simple way.  Digital values don't drift, have offset errors, change over temperature, and generally are a lot more precise than analog.  Firmware also allows for various non-linear schemes that would be difficult in analog.

It seems the natural thing to do is to run a control loop iteration each error waveform peak.  Capture the peak, and that is you error level for that iteration.  The tricky part may be to determine the direction of the control output.  Is there a phase reference so you can get a signed error value instead of the absolute value?  That would help a lot.