Why is transistor needed when using a relay?
Image from linked question: -



Basically the opto-coupler cannot provide enough current at low enough voltage drop to turn on the relay coil shown. The transistor acts as a power buffer and it "delivers the goods" with a small input signal power from the opto-isolator.

Addition

You may be able to replace the opto, the transistor and the relay by using Panasonic's PhotoMOS product range: -



Pick the DC/AC contact rating you need and the isolation voltage and if it fits your application then you're good to go.