The circuit below will drive a 12v motor using an optocoupler. In the circuit PC817 is used but how do you know which optocoupler to use?
Start by choosing a "gate drive" push-pull optocoupler and you almost can't go wrong. I would choose one with a supply voltage of 30 volts or so to give yourself some margin running a motor. You may need a resistor on the input side to limit diode current. The PC817 you have chosen is a poor choice for anything except a low speed, on-off switch because when you turn it off, you are relying on the 10K pull-down resistor to drive your MOSFET gate.