Although I prefer to deal with some facts before sticking my neck out.......:0)............the fact you can hear a noise when the key is off indicates you might be hearing the shift motor on the transfer case running.
Why do I suspect that........because I have seen this before on some of the trucks.
The shift motor is controlled directly by the TIPM or totally integrated power module. This is the part that houses all the fuses under the hood.
Since there would be no power with the key off, it tends to make me think that the TIPM has an internal failure and is engaging the shift motor on its own. This could also explain why it shifts in 4wd. On its own when you are driving.
So, the codes in the TIPM would be the first thing that I would investigate but I would also like to scan all the modules on the truck to get a full picture of what is occurring, code wise.
A scan tool that is capable of reading all these modules is basically a professional quality tool that starts at about $2K and goes up from there. Snap on and OTC are 2 of the favorites but there are also many others. Unless you plan on investing that sort of money it likely isn't a cost effective way to go about this.
One alternative, if you are trying to repair this yourself, would be to simply have a shop do a full scan for you and get a list of all codes stored, and then we can work together to decipher what is occurring. Depending of the rates in your area, you might may $100 for a scan, so let me know if this is something that would work for you or whether you prefer to handle this yourself without the benefit of getting the codes.
Please reply back before rating, if you need further assistance.