Most country's citizens are granted a 31-day visitor's visa on arrival upon presentation of a passport with at least six months' validity and an onward ticket. Those intending to fly in and depart Tongan waters by yacht require a letter of authority from one of Tonga's diplomatic missions overseas or the Immigration Division.
You can extend your stay for up to six months at any immigration office; each island group has one, usually located next to the police station in the main town. In Nuku'alofa, this is handled by the visa and naturalisation section of the Immigration Division (26969; fax 26971; Salote Rd; 9am-12.30pm Mon-Fri, 1.30-3pm Mon, Tue, Thu & Fri), opposite Cowley's Bakery. You'll need one passport photo for each extension (T$46) and a photocopy of your onward ticket. You'll need to show evidence of sufficient funds for your stay in Tonga, though a credit card is often enough.