The best way is to have it on a network with channel services that can make it possible to deal with that situation. If you aren't on a network with channel services, the only option would be to have multiple bots or people who will automatically re-op the bot if it gets de-opped, and even then it's not foolproof.
In the end, if you are concerned about that, then you should reconsider who is allowed to be an op. Don't op anyone who you think will de-op the bot.