Relays can isolate mains from your device, but you need good quality or special relays to do it safely. Some relays are safe now but not after a month or a year(s).
There are driver chips for your problems. Like ULN2003 and so on, or 2N7000 is driver fet for making it easier for the CPU.