It's not the fuel pump when you get out of the car - I'm referring to when you're getting into it, particularly if it's been turned off for a period of time. The LPFP runs for several seconds to prime the HPFP. Sort of a high-pitched/electronic humming sound. That's what it is in my 07 E92.
Regarding noise after you turn the car off, it could be your electric fan spooling down. The LPFP doesn't run after you shut off the ignition.
2013 F30 335i M-Sport 8AT/MPE/MPPK, 2016 228i M-Sport Cabrio 8AT