Both words refer to a self-contained residential unit with its own front door, kitchen, toilet, and bathroom. In some parts of the world, the word apartment refers to a purpose-built unit in a building, whereas the word flat means a converted unit in an older building, usually a big house. In other places the terms are interchangeable.
The term apartment is favored in North America (although in some cities flat is used for a unit which is part of a house containing two or three units, typically one to a floor). In the UK, the term apartment is more usual in professional real estate and architectural circles where otherwise the term flat is used commonly, but not exclusively, for an apartment on a single level (hence a ‘flat’ apartment).
In some countries the word “unit” is a more general term referring to both apartments and rental business suites. The word ‘unit’ is generally used only in the context of a specific building; e.g., “This building has three units” or “I’m going to rent a unit in this building”, but not “I’m going to rent a unit somewhere”.
Some buildings can be characterized as ‘mixed use buildings’, meaning part of the building is for commercial, business, or office use, usually on the first floor or first couple of floors, and one or more apartments are found in the rest of the building, usually on the upper floors.