Can you and/or why should you not replace optocouplers with transistors when dealing with slightly different voltage
You have optocouplers for both transmit and receive. The voltage difference by itself could be worked out with resistor dividers, or a simple transistor circuit if a boost in voltage is needed.

The reason optocouplers are widely used regardless of voltage differences is that they isolate grounds as well for galvanic isolation. You may have heard of 'ground loops' where the signal and/or Earth ground of different pieces of equipment are not the same.

Some equipment has an isolated ground, especially if powered by a wall-wart. Those with an isolated ground can have small non-hazardous leakage currents that may cause problems with data links, so using optocouplers isolates the "grounds" to prevent any ground loops.

Also equipment that is Earth grounded but at distant AC outlets may have enough current difference in their grounds to induce noise in direct coupled comm ports. Some ask you to run a separate signal ground from device to device to avoid drifts in a common 'signal' ground which often has a medium value resistor tied to Earth ground. RS-232 and RS-485 (multi-drop) ports have a signal ground shared by all connected ports, though it has a high impedance Earth ground by using a resistor high enough so it is only a 'static' reference.

I worked with surge generators for 15 years to simulate lightning strikes, and when it fired a 27,000 volt pulse at 20,000 amps our earth ground wire that went to an isolated ground rod had for a brief time (20uS) 1/2 of the surge voltage on it, or -13,500 volts on it. The oscilloscope had differential inputs and we used probes rated for 75KV, but we had to use an opto-isolator on the GPIB bus to the computer, or we could fry the GPIB card in the PC. We installed the isolator after 2 fried GPIB cards. At times the optocouplers save equipment from real damage.