Team A is with the ball and attacking. Team B is the defending team.
Can team B play an advantage on an offside by team A?
From page 72 of FIFA's 2013-2014 Laws of The Game:
The referee may play advantage whenever an infringement or offence occurs.
This would include offside, which in Law 11, is considered as an "offence".
Traditionally (up until a few years ago), referees could only play advantage from fouls and misconduct (Law 12 offences) and infringements that occurred during the taking of penalty kicks (Law 14 infringements).
This was not written in the laws, but was considered common knowledge.
Yes, it is the referee's discretion to respond to the linesman's flag and stop play or to play on if advantage is apparent.
Addition to @rajat's answer: it usually happens in the case where the attacker actually doesn't even run to the ball, or the ball going too fast/high for the attacker to get to.
It is however unusual that there is much of an "advantage" in that, as it's rare that the defending team suddenly gets into an attacking position which would justify playing an "advantage".
Normally referee blows the whistle as soon as he sees the linesman's raised flag, as late offside calls are tricky for both attackers and defenders. If the flag is slightly delayed and the defending team is not being threatened by the attack anymore, the ref may choose to not stop the game for the sake of flow.