I don't think it is possible to avoid giving offense unintentionally, obviously (to me) that is possible even if you think hard about not giving offense.
I also don't think it is reasonable to demand we give no offense to anybody: My daughter was offended, in Django Unchained, that one of the characters intentionally shot and killed an innocent (and healthy) horse. Of course no animal was harmed in the movie, it was a special effect. And she wasn't upset about the hundred humans "killed" in the movie. Just the horse.
Well, sorry kid, the plot demanded it. And it is true the plot could change to not demand it, but that would probably have taken more screen time, shooting the horse was quick and expedient.
A similar argument, I think, applies to pedophiliacs, rapists, serial killers, terrorists, sex slavers, White Supremacists, Nazis and brutally violent criminals, Mafia, hit men, drug lords and gang members.
All these people exist IRL, and have victimized and killed innocents, including children. It is pretty much the nature of fiction that such monsters are shown being successful, and getting away with their crimes, even laughing at the pain and suffering they have caused, or as they cause it. That may offend people that have suffered their predation, or have lost people to such predations.
But fiction isn't compelling if their callousness and crimes are not shown, fiction needs bad guys the audience hates, the bad guy can't always be a businessman that threw his half-eaten sandwich into the "plastics only" recycle bin.
(Sorry if that horrified anyone; proper recycling is an important responsibility.)
That's what I think you can't control. However, I think most of us can recognize superfluous offense, and eliminate it. If the racism, bigotry, prejudice, misogyny, homophobia, anti-semitic rants and other fictional slandering doesn't serve any real plot purpose (or some plot point is shoe-horned in to justify it, and could easily be done some other way) then it can be eliminated, and should be eliminated.
I think, as a writer, we should look for ways in which we may give offense, and educate ourselves in ways we may give offense, and decide if our story needs that, or if we are just stupidly perpetuating some deep prejudice learned when we were younger and dumber, when our culture was younger and dumber.
Sometimes offense components are necessary to tell a good story, make a good villain, or even make a good hero that can change for the better, or be redeemed. But that doesn't give us license to offend at will for no good reason.