Assuming the airport provides ground power at the gate, will the Auxiliary Power Unit (APU) be started and used after landing? If not, I guess the engines will only be shut down when the Ground Power Unit (GPU) is connected. In this case, how do pilots know that the ground power is connected, so that they can shut down the engines?
How do pilots know that the ground power is connected?
The ground crew hooks a headset to the plane to communicate with the flight deck.
Once the ground power is connected, they confirm it, also a light comes on in the flight deck confirming external power is now available.
(Source) Ground power switch and light on a Boeing 737.
In a twin-jet airliner, they usually (subject to company) taxi-in with one engine, the other being shut down after it had time to cool down after the reversers are stowed.
They usually shut down the number 2 engine, the starboard side, where the GPU and other ground crew members approach the plane as soon as it is parked.
Many airports have restrictions with regard to keeping the APU running at the gate, due to emissions and noise, unless the plane is pushing back.
Responding to the first part of your question about starting the APU at arrival.
Soon after landing the APU is usually started to provide a seamless electric power transfer and cabin thermal management (cooling and heat) prior to main engine shutdown. Otherwise the aircraft will need to be plugged in electrically and have a large duct attached to provide cabin comfort.
If the APU is operational we always start it before we arrive at the stand. One of the main reasons for this is to ensure that we have an active bleed source before we shut down the engines. Why do we need a bleed source? Because when the engines are at idle power (during start up and shut down), in rare occurrences excessive fuel in the combustion chamber can cause the fuel to light up and send flames through the engine exhaust. We call this a tailpipe fire https://www.skybrary.aero/index.php/Tailpipe_Fire. If a tailpipe fire occurs, you need to ventilate the engines and for that you need a bleed air source. The APU when started can provide it immediately and help to get rid of the excess fuel by turning on the starter without switching on the fuel.
In airports that require the shut down of the APU (mainly to minimize noise pollution) we still turn it on so that we have power available until the GPU is connected. The GPU will be connected by the ground crew once the engines are turned off. Once it is up and running, the engineer will contact us using his headset and will ask to turn on the external power and shut down the APU. As soon as we get the green light we turn on the external power and turn off the APU. To cool the cabin, usually an air conditioning unit is also connected to the aircraft.
So, what if the APU is inoperative? In this case, we always notify the station we are flying to about the status of the aircraft. We simply tell them that our APU will be inoperative and we require the GPU on arrival at the gate. At the gate because with engines started no one can approach the aircraft. So, we use hand signals to alert the ground to get the GPU connected. The hand signal for GPU connection is shown in the picture below. You basically make a T signal using hands.
To allow the connection, we shut off one of the engines. In most airliners, the number two engine is shut down, so that the ground crew approach and can connect the external power from the right of the aircraft. With the GPU connected the remaining engine is shut down. If you were to shut down the engines without connecting the aircraft to a power source, the aircraft will revert to the batteries which will turn off all the lights and most of the cockpit displays. It is not what exactly you want to happen.