The three letter codes are International Air Transport Association (IATA) codes. IATA is made up mostly of airlines, and they’re generally more “friendly” in terms of relating the code to the airport.
The four letter codes are International Civil Aviation Organization (ICAO) codes. ICAO is made up of the governing bodies from countries and regions around the world. These codes are more structured (e.g. one and two letter prefixes for countries).
For most airports in the continental US, the ICAO code is just the IATA code with a K (the US’s country code) added to it; if you enter the IATA code (for an airport in the continental US) into FlightAware, it will automatically prepend the K.
For Alaska and Hawaii, the ICAO prefixes are PA and PH, respectively. The first two letters of the IATA are then added to this (OGG becomes PHOG, FAI becomes PAFA); the exception is when the IATA code begins with an A or H (in the “right” state), where you keep all three letters of the IATA code and prepend a P (HNL becomes PHNL, ANC becomes PANC).
It appears that Argentina (country code SA) is following a similar pattern.
Some countries (China and Japan come to mind) will assign their premier airport the code AA, presumably to be first on the list. For exampe ZBAA (Beijing Capital) and RJAA (Tokyo Nartia).
And then there are the pilots who file the wrong code. I’ve seen KANC and KHNL.