Remove one of the 4 GB strips of RAM so that you are only using half of the total 8 GB that you say you purchased. Does the system run stable? If not, replace that strip of RAM with the one you removed. If the system is still not stable, remove that strip from the slot and insert it into the other slot. If this still does not solve the problem, you may want to try a different brand of RAM.
Chances are this is a bad power supply board.
Shutdown error codes can be negative or positive values; negative being hardware and positive being software.
A "0" code is right there in the middle where it usually means a sudden loss of power. See this post for more info: Are OS X shutdown cause and sleep cause numbers listed/explained anywhere?
If any part of your logic board was beginning to fail, it would generate kernel panics which would be in the log and likewise, if you had software causing issues, there would be a log of a crash somewhere.
I've see this previously on other platforms whether it was a Mac, or a PC, or even enterprise grade servers. What is probably happening is that a component in your power supply is getting too hot and consequently shutting down. If you take it to the Apple store, they probably have the ambient temperature much lower than you home so it never has a chance to over heat. Just when you think everything is good, the symptoms return.
Is your downstairs location warmer or cooler than the upstairs location where it normally resides?
If you need to replace your power supply, rest assured these are fairly easy to come by and fairly inexpensive. At the time of this post, they were trending around $65. It's also very easy to replace (see the guide at ifixit.com)
While you are in there, I would swap out your (spinning) HDD with a SSD. I just installed a Samsung 850 EVO SSD in my 27" iMac and it is substantially quieter and cooler than before.
Disclaimer: There still is a chance it's the logic board, but it's highly unlikely. Before you do any expensive logic board replacements, try replacing the power supply first.
One more thing....I would definately follow agentroadkill's advice from his comment and put a UPS (battery backup) between the outlet and your Mac.
Best Answer
I can't imagine the Apple Store haven't already done this - but have you/they tried resetting the SMC?
For iMacs, the steps to do this are:
However, assuming they have already tried this, there are other things they can do, such as swapping over the logic board.
Troubleshooting is a process of elimination, and you know that reinstalling macOS doesn't resolve the issue, and neither does replacing the RAM. So, if it was me, the logic board would be next.
Let us know how you go.