First, use /whitelist add (player) to add yourself to the whitelist. for bedrock players, use /whitelist add *(playername). Opped players can bypass the whitelist, so make sure to deop anyone you don't want bypassing the whitelist.
Then, enable the whitelist using /whitelist on. When you want to disable it, use /whitelist off.