if you can find the cpu for sale, sure, though since you're stuck on a z series motherboard I'd probably spend an extra few bucks for the k series cpu..
Yeah the i5-8400 is a 100% solid choice, and if you can get all cores to work at max boost of 4ghz, it'll be an amazing chip.
However, enabling MCE makes that CPU to generate a lot of heat, so make sure you get a good cooler if you plan doing that. Stock cooler might not be enough.