open System Preferences > Bluetooth and enable the option Show Bluetooth in Menu Bar.
Hold down the Shift and Option keys (Alt on some keyboards) and at the same time click on the Bluetooth icon in the menu bar. Once the menu is showing, release the keys.
From the Bluetooth menu, choose Debug > Remove All Devices.
Repeat step one, then from the Bluetooth menu, choose Debug > Reset the Bluetooth Module
Reboot your Mac, then setup your keyboard and/or mouse as normal.