Switching relay directly with an optocoupler
I wanted to know if I can directly run these relays with optocouplers
such as PC847.

The simple answer is yes but, you will waste a lot of power driving the internal opto LEDs. In fact, you will use more current driving the internal LED than what your relays need. Consider this: -

To drive 7 mA through the phototransistor (\$I_C\$) with low volt-drop (say 0.6 volts) requires an LED drive current (\$I_F\$) of 7.5 mA and this is just a typical device; to guarantee that all devices work you should be aiming to drive \$I_F\$ at twice this value i.e. your STM32 ought to be pushing 15 mA into each opto.
That's over twice the current needed by the relay and may actually exceed what is allowed from the STM32. Of course you might get away with 10 mA but then, you might be scratching your head when a couple of channels don't work properly. How much do you value your time is a question I sometimes ask in this situation.
Compare this with an NPN transistor and a base resistor (much more efficient and much less base current needed) and the comparison numbers don't really stack up but, you may have &quot;special&quot; reasons for going down this route.
Both solutions will need flyback diodes across the relay coils.