first if you are getting message that your battery needs service, you want to get it looked at either by going to apple store or service provider.
try doing an SMC reset, the following article tells how:
after this reset restart the computer and see if it works normally if it doesn't see below.
second regarding the restart of your computer, it could be a kernel panic. the following article tells how to troubleshoot this issue:
if after following this article the mac continues to restart try running the apple hardware test to see if there is a hardware issue:
if none of the above steps resolve your issue i would take to apple store or service provider to have it serviced.