Kids at this age are learning and pushing boundaries. Swearing is not acceptable, but for some kids it's a normal thing they hear, and it's natural that they would "try it out" to see what they can get away with. A firm reaction about it not being being respectful or appropriate is the way forward, and if it continues, escalation up t the next stage of the school's disciplinary process.
As for toileting... well, sometimes you just have to go. Kids DO get preoccupied with games, playing and other activities, or even difficulties at home/ school resulting in forgetting, or sudden urges. If it's not a regular thing - in which case I would be asking questions about their medical status and /or classroom experiences - I don't see a problem with letting a child in need go to the loo. Lot's of kids don't have prolonged bladder control at that age, and noticeable wetting when they get too desperate is both humiliating for the child, and annoying for the adult. Not to mention that prolonged holding can cause a lot of discomfort and later difficulties for the child.
Maybe this child has had a problem? maybe they got bullied in the restroom and would prefer to go when others aren't in there? Maybe they have shy bladder? Or maybe they just plain old weren't listening when you reminded them......
If you think kids need to show respect, you're in a position to respectfully and gently teach them what that means.
Although, all of the above doesn't really address the interesting point of why this issue is being brought up on a Mental Health forum?