universal input schematic
A different power supply, for auxiliary signaling is usually to be use in such cases.
Don't forget, that even if you use optocouplers, you only break the possible ground loops, but still there is a path for high frequency noise trough this optocouplers. Design your inputs with this in mind. Use RC snubers, varistor protections etc after optocouplers, and good EMI shielding. Also, it is advisable to use optocouplers for the outputs (between the I/O line of MCU and relays) and supply voltage to the relays coil from a different power suply. Also RC snubers on the relays contacts are advisable. Even so, you can have problems if you switch high inductance loads.