problem with driving the mosfet through optocoupler
simulate this circuit &ndash; Schematic created using CircuitLab

Is a circuit that should work for you. D1 and Q1 are used together to form the opto isolator. The values are just ball park, the schematic is just meant for topology purposes.