Warning, there are spoilers in this answer if you haven't watched SAO completely yet.
For the SAO arc, outside of towns, you're constantly "flagged" for PvP. From the beginnings, when you're getting explained how the players are divided:
Inside the city, or the places mostly referred to as «Safe Areas», there was protection implemented by the system and players couldn't hurt each other. But it wasn't like that outside. The stragglers made teams with other stragglers and ambushed other players —which was in many ways much more profitable than hunting monsters— out on the fields or the labyrinth areas.
Players that commit crimes are marked orange (i.e., their cursor turns orange). From when Kirito and Asuna encounter the troop from The Army in the forest:
More importantly, whenever a player committed a crime, their cursor would turn orange and wouldn't turn back to green for a long time.
Note that attacking an orange player doesn't change your cursor to orange. From when Asuna steps in to stop Kuradeel from killing Kirito:
Kuradeel bounced back up as if he had springs and attempted to form an excuse with his nervous voice. But before he could finish, Asuna's right hand flashed and the tip of her sword tore Kuradeel's mouth. She didn't become a criminal since her opponent already had an orange cursor.
Inside of towns, you have the town protection in place, which doesn't allow open PvP, so many new players originally stayed in town to be safe. You can attack other people in towns, but it won't do anything except for some special shiny effects and knockback.
If players engage in duels, there are several options:
The other options are not explained or mentioned as far as I can see.
For the ALO arc, there's PvP against other fairy races in your native race's (controlled) towns. From when Lyfa/Suguha shows Kirito around meeting Sigurd:
Somehow, a circle of onlookers had already surrounded them, drawn by the signs of trouble. If this was a formal duel, or if he were an actual Spriggan spy, then fine. But it would be dishonorable if Sigurd instigated a fight with a tourist like Kirito, who can't even fight back in this area.
And in that same quote, it's mentioned that a "formal duel" is possible, but that's not further explained. Outside of towns, you can fight without restrictions. This can be seen by people just fighting about everywhere. Note that if a race's lord is killed by another race, the other race will gain control over that lord's territory. From when Lyfa explains why the Salamander want to stop the Sylphid-Cait Sith alliance:
"Also, if they kill the Lord, they will get some amazing bonuses. They will unconditionally receive 30% of the lord's funds stored in the mansion, and for ten days, the territory that the lord rules over would become occupied, then they are free to set taxes and take that money. That is a tremendous amount of money. The reason why Salamander became the largest force in the game was because in the past, they had set a trap for Sylph's first Lord and killed him. Normally lords don't venture into neutral territory. In the history of ALO, only one lord has ever been killed."