The code could be pretty much as kwacker has suggested (obviously not pseudo-code though). I'd use timer interrupts.

Using two of the PIC's pins to control Vref is a neat idea - and two trimmers should be fine.. You could use a third pin with a trimmer for configuring the timeout (should be very easy to do).