Opto Isolators provide a way of separating your low voltage, safe, logic signals from the terrifying, death inducing danger of the mains electricity supply. Inside each of these chips one 'side' contains an LED, the other 'side' a photo-transistor.
When current is passed through the LED and it produces light, without any *physical* connection, it allows current to flow through the photo-transistor.
This means that your Raspberry Pi, or Arduino should never suddenly 'go live' with mains voltages.
The optocoupler (another name for the same thing) can also be used for AC mains detection, reed relay driving, switch mode power supply feedback, telephone ring detection, logic ground isolation and logic coupling with high frequency noise rejection.