Scotland can't leave the UK and remain in the EU. They would have to become independent and then begin the application process, which could take years. There's a real possibility that some EU members will oppose their application.
EDIT:
"UK Government could use Article 48 of the Lisbon Treaty to apply for a treaty change which would allow Scotland to become a member when it formally becomes independent in 2016.
The Article 48 route has been dismissed by the UK Government and it would also require unanimous approval of all the other 28 EU members. Instead the more likely route is Article 49 which requires Scotland to apply for membership."
This is just from some light Googling, some more informed people may have more details
EDIT:
"UK Government could use Article 48 of the Lisbon Treaty to apply for a treaty change which would allow Scotland to become a member when it formally becomes independent in 2016.
The Article 48 route has been dismissed by the UK Government and it would also require unanimous approval of all the other 28 EU members. Instead the more likely route is Article 49 which requires Scotland to apply for membership."
This is just from some light Googling, some more informed people may have more details
from http://www.scotsman.com/scottish-independence/key-topic/euro...