Missed this post earlier...
3 displays is easy, and the latest 27" 5k iMac has your back. Four displays is another issue. Four displays isn't supported by the iMac, though I haven't tried daisy-chaining. Still, no-way you'll get 4x4/5k, because the iMac GPU won't take you there, is my guess. Again, only 3 are officially supported.
I did get four displays running on a maxed out new 15" rMBP, but that was: 2x27" 1440p (Mini-D), one 1080p (HDMI), and the rMBP's own display. But I'll say that that little rMBP's fans started howling too fiercely for my liking. I wasn't doing anything too intensive, just my normal workload, but I didn't get the sense that it was happy.
But 4 displays, especially if they're 4k, is Mac Pro country. I would advise you, however, to get a better feel for what 4 displays is like, before jumping on it. My workspace was built for screen real-estate (as in I built a shed/home office in my back-yard), and I do run 7-8 large displays in a very wide U-shaped area. But I have a couple systems going there. I'd say that practically, three large displays is about what my eyes can deal with, though 4 is close. And I am about to transition to 4 on my main system, though the far-right display is likely to be special-purpose. In other words, I'll have to slide my chair to the 4th display in order to really use it, and it will need its own keyboard. Again, this screen will be for special-purpose tasks, though it will be on the same system.
Another thing is that with three displays, you can arrange them in a U-shape. The effect of having the two side displays angled into you is that your face is always somewhat near the screen. WIth four displays, you tend to have to be somewhat flat, which means that one or two displays will be pretty far form your face.
As a fellow pixel/screen real-estate whore, all I'm saying is get a sense for what the workspace will be like, before investing money. It might sound goofy, but cut out a few pieces of cardboard to get a feel for what working with all of that will be like. This, because the difference between three and four displays, especially in the Apple world, is a big jump.
I will also do some gaming on it and if the 40" doesn't do the job I most likely will go to a multiple monitor setup, like 4 28" displays.