Ouch! This is a tricky one!
The logic board has a problem, the question is if its repairable or will you need to replace it.
As you state it works sometimes then you might only need to find the cold solder joint(s) it has and after fixing that you may be good. You’ll need to remove the logic board and do a good inspection looking for any liquid damage and/or corrosion as well as check the solder joints.
Do you have the needed skills and tools to do this? If not you might want to find someone locally or just replace the logic board which is not overly expensive given the fact you got the system for free ;-}
Right now iFixit has a 8 GB board MacBook Pro 13" Retina (Mid 2014) 2.8 GHz Logic Board You might find the 2.6 GHz Logic Board for less. If you can I would try to get the 16 GB if you plan on keeping it for a few years as it would be a better investment.
In anywise heres the guide to replace it MacBook Pro 13" Retina Display Mid 2014の基板の交換