I don't understand how air traffic controllers can choose the right flight level and heading for airplane when they are in the sky or they're approaching the airport to land.
During the enroute portion of the flight at cruising altitude, pilots will have filed a cruise altitude and route based on airplane performance and weather. ATC will not need to change this unless the pilots ask to deviate or there would be a separation issue. Separation will depend on the local regulations and type of airspace and aircraft involved. For airliners this is usually 3 miles laterally or 1,000 feet vertically.
Pilots may request deviations from their filed route due to weather or other reasons. ATC will look at other traffic in the area and determine what changes can safely be made. ATC may also need to give altitude changes to keep them clear of other traffic. If two planes are converging at the same altitude, at least one of them would need to climb or descend.
When arriving at the destination, many airports have stardard terminal arrival (STAR) procedures that pilots use in their route and may give route and altitude instructions. ATC will also have standard procedures for routes and altitudes that will allow arriving aircraft to descend without interfering with departures or other airspace in the area.
This seems a broad question to me, as the answer to both questions is it depends and answers can expand endlessly. As the community hasn't voted it as "too broad" I will attempt to answer, although I'm afraid that it will be a "stapling" of other questions of this site.
Let's start by clarifying one common misconception. There is not "one ATC unit" there are several: When a plane is close to a controlled airport, it's controlled by tower. After takeoff, by approach/departure; during cruise by en-route control ("Centers" in the US, "ACCs" in Europe and I don't know for the rest of the world) and during landing it's again approach/departure, and then tower again. For more information you can have a look at this answer which explains these concepts in depth.
This is irrelevant to the question but why do I mention that? Because an approach/departure controller's job is significantly different than the one in ACC. As a result they assign headings and altitudes in a different manner.
abelenky in their answer mentions the "even-odd rule" for altitude assignment which is correct. But if want to go deeper, this is not entirely true: above FL410 ("41000" feet) flight levels are every 2000 feet. So 410 is the "odd" and 430 is the "even" (ie the westbound). And that was after RVSM. Before RVSM, flight levels were every 2000 feet from FL290 up to FL410.
and every 4000 feet above FL410. Again the "even and odd" was redefined. More information on RVSM on this answer.
There are cases where the pilot can request to be exempted from RVSM. Severe turbulence is one case, although I've heard that disengaging the autopilot is not the first option; it's an altitude change request I guess mostly because ATC can easily decline you the request to be exempted.
Also air traffic controllers can offer to pilots an opposite(1) flight level (specifically mentioning
opposite in the phraseology) where the pilot can either accept or refuse.
Usually when a flight receives a departure clearance, it is assigned a runway, a SID and an altitude. This altitude might be dictated by many factors like the SID itself, the terrain around the airfield and the traffic around the airfield at the time of takeoff. For the last case, the controller's judgement call is required.
After departure the controller will try to clear the flight at the predefined handover altitude with the ACC. If that cannot be reached on time, a coordination needs be done between the 2 controllers.
When the aircraft is in the ACC's control, the controller will again try to direct the aircraft to its final requested level. Usually, upon first contact of a departing flight the controller will ask
foobar flight say final requested level and the pilot will report it back. The requested flight level (RFL) is included in the flight plan, but for some reason that I've never asked why they ask the pilot when they get them on frequency.
After that and until the top of descent there is no significant change in altitude. At the top of descent the pilot will request a descent and the controller will grant it whenever it's safe and possible. And then the reverse process starts: get the flight at the predefined altitude for handover with the approach, and then the approach will try to descend the flight to the appropriate altitude for engaging the ILS or other instrument approach procedure.
Before departure a flight is assigned an SID and they are supposed to follow it, unless they receive an instruction from the controller to deviate. When discussing with air traffic controllers in LGTS, they told me that the majority of the flights are assigned a "direct" to the TMA boundary. They assign a heading only if there is traffic in the vicinity and want to steer the departing flight away of it.
During arrival as it is correctly mentioned by fooot's answer a flight is (usually) assigned a STAR, which they follow in order to engage the IAP that will get them safely to the runway. In airports with RADAR service though, the approach controllers are vectoring the flight in order to create a stream of aircraft, a queue for landing. In order to keep this post short (too late I'm afraid) and because I don't want to repeat myself, I invite you to read my answer on the topic here. Then you can see if you still have blurred areas and you can post a new and more specific question.
During en-route control the flights fly on airways. The routes they follow though are not always great circle arcs. So very often the pilots are tempted to request a direct to point to save some miles, and along with that fuel, emissions and time (so everybody is happy). The controller again might or might not grant the direct depending on the situation.
All the above make the profession of the air traffic controller sound very easy: just a cool and relaxed guy giving predefined altitudes and headings. Nice... But that's far from the reality. Many times things don't go as planed and flights on the same altitude converge and the controller has to take actions. They have to evaluate each case and decide which technique they will follow to resolve the conflict: altitude change or vectoring?(2)
Even worse there might be 2 flights not on the same altitude climbing or descending and still converging and these are more difficult to detect. Remember when I mentioned the differences between approach and en-route controllers? Here is a good opportunity to explain it: An approach/departure controller (usually) has a smaller area to control than the ACC controller. Both vertically and laterally. That's why they can grant a climb from 4000 or 5000 feet to the upper limit on the TMA (which might be up to FL250) more easily. But an ACC controller has to be more careful: once they receive the flight they have to climb it incrementally. At higher altitudes the climb rate degrades and the speed increases rapidly. The plane will take longer to reach the RFL. If they grant the RFL very soon, how can they be sure, that many nautical miles away (might be from 100 to even 200 depending on the circumstances) there isn't an opposite or crossing flight that will come by and bite them?
Believe it or not this is the short version of the answer. You can take each and one of the paragraphs and expand them to infinity. Feel free to post new and specific questions if you would like to know any details. As you can also see from the links, most of the questions are already asked, so feel free to make a search first. I hope this is helpful.
(1) westbound FL for an eastbound flight and vice versa
(2) and some times speed control but let's keep it short(er).
There is a rule that planes flying East should travel at odd-thousands of feet (19,000; 21,000; 23,000; etc), and planes flying West should travel at even-thousands (20,000; 22,000; 24,000; etc).
There are wind-forecasts made daily using weather models, radar, balloons, and other observations to figure out which way the wind is blowing at different altitudes. Whenever possible, planes try to fly with a tailwind to cover more ground faster.
Pilots can request the altitude they want to be at, and provided ATC sees that will not put them too close to another airplane on radar, a pilot request will generally be granted.