Using an Opto-Isolator to change an Op-Amp's Amplification
Assumption: There is some need for optical isolation between gain control (uC output) and amplification module.

Here is a simplification of the approach in the question, that removes any transistors / FETs from the feedback path, and provides an analog (continuous) range of gains, while retaining the opto-isolation - Use an LDR optocoupler as used in some classic and DIY audio amplifiers: 



For a one-off or DIY alternative, use a cheap and ubiquitous CdS light dependent resistor instead, coupled with a regular LED:



The schematic is thus:







simulate this circuit &ndash; Schematic created using CircuitLab

The gain controlling resistance is the parallel combination of R1 and (R2 + R_LDR). 

By varying either the duty cycle of a PWM signal, or the voltage of a DAC output pin of the microcontroller, the LED's light intensity is varied. As this increases, the LED resistance drops, from a very high value (i.e. little effect on gain calculation) when the LED is off, to a low value when the LED is at nearly 100% duty cycle.

Note: If using PWM, the PWM frequency needs to be significantly higher than the frequency band of interest of the signal. Otherwise the PWM will couple into the signal path, as pointed out by @pjc50.