An electrician is your friend here. You need to do it right or you could be flirting with big trouble. Always remember to shut off your main breaker before starting your generator. Otherwise you risk hurting or killing a utility worker down the line.
That’s what the transfer box is for. It switches off the mains when the genset is running. The transfer box can be automated.