It is vulgar. It's okay to use with friends, but it can have both a positive and negative tone.
Negative tone:
Your friend has a bag of sweets, and you ask your friend if you can eat some. You eat more than half of the bag, more than your friend expected you to take. Your friend says 'you're taking the piss'. From this you should know that your friend is unhappy, because you ate so many of his sweets.
'Taking the piss' in this context can mean 'taking advantage'.
-----
Positive tone:
Your friend spills water on his trousers, around the crotch area. You laugh at him and shout 'haha he wet himself'. Your friend may ask you 'you taking the piss?!', or you can say to him 'no not really, I'm only taking the piss'.
In this context, 'taking the piss' means 'only joking with you'. (Like what Equis.Lung said)
---
Another negative tone:
If you and your friends are joking around, someone may say or do something which is perhaps a little too offensive than intended. Someone can say 'you are taking the piss now'. You should know from this that you have done something which is offensive, you have overdone the joke and now it is no longer a joke but an insult.
In this context, 'taking the piss' = 'overstepping the line', 'going overboard', 'taking a joke too far'.
---
Really, this is mostly used with a negative tone. You would be really good friends to use this with a positive tone.