How to float the output of an optocoupler when needed?
You could connect a buffer like SN74LVC1G240 instead of the transistor to control the output of IC2.

The output of IC1 goes to the Output Enable input of the buffer.
The output of IC2 goes to the A input of the buffer.

When the EN is high, the output of IC1 is low, enabling the buffer output.
When the EN is low, the output of IC1 is high, disabing the buffer output (floating).

I think this should work, but please double-check before ordering parts ;-)