The pullup resistor R4 and the Q1 gate capacitance form an R-C circuit that determines how quickly Q1 turns off after the U1 output goes open-circuit. If you have a maximum turn-off time in mind, that sets the maximum value for R4. A 10 K resistor should be fine.
To protect the gate, consider a 20 V zener diode from gate to source, AND a resistor from the gate to the U1 output. As before this creates a voltage divider, but this time the added resistor is much smaller than R4. Its job is to limit the surge current into the U1 output stage when the output is low and Vcc spikes upward above 20 V. If Vcc spikes to 40 V, a 1 K resistor limits the surge current to 20 mA.
ak
To protect the gate, consider a 20 V zener diode from gate to source, AND a resistor from the gate to the U1 output. As before this creates a voltage divider, but this time the added resistor is much smaller than R4. Its job is to limit the surge current into the U1 output stage when the output is low and Vcc spikes upward above 20 V. If Vcc spikes to 40 V, a 1 K resistor limits the surge current to 20 mA.
ak