Facing the challenge of making an isolated DAC output I found a circuit by Kerry Wong (http://www.kerrywong.com/2013/10/01/an-isolated-dac-using-pwm-output/). Unfortunately, it did not work as I hoped. The optocoupler I used, a PC817 turned out to be too slow. It took some 20 us for the transistor to get out of saturation. After replacing the coupler with a 6N135, speed was no longer a problem, however I did not quite like the 50% threshold level of the first opamp. So, I changed that to an 'automatical averager'. This worked OK, except for low duty cycles, the output would not go low enough. Adding a little feed-forward on the automatic threshold did the trick. Now the output voltage is nicely linear (from 0 to 5V) with the input duty cycle. Thanks to Kerry for the inspiration!