The meaning of the verse
Hasbunallahu wa ni'mal wakil meaning: «hasb» means to be sufficient, and «wakil» is the one to whom affairs are entrusted and who takes care of them. Verse 173 tells us that when people said to the believers that the enemy had gathered a great army against them, so fear them, this news only increased their faith, and they said: Allah is sufficient for us, and He is the best Disposer of affairs. Verse 174 describes the result: they returned with blessing and bounty from Allah, no harm touched them, and they followed what pleases Allah.
Background
According to the scholars of tafsir, this event took place after the Battle of Uhud. In Sahih al-Bukhari, Aishah (may Allah be pleased with her) relates that after Uhud, when there was a fear that the idolaters would return, the Prophet ﷺ called for people to pursue them, and seventy Companions answered his call, among them Abu Bakr and al-Zubayr (may Allah be pleased with them). Aishah said that the verse before this one, verse 172, refers to them. According to one view, verse 173 is connected to that same journey to Hamra' al-Asad, and according to another view, to the occasion of Badr al-Sughra (the Lesser Badr) the following year, when frightening news was spread on behalf of Abu Sufyan.
Key lessons
This verse teaches that a believer does not grow weak on hearing frightening news; rather, his trust in Allah grows stronger. Tawakkul does not mean abandoning the means; the Companions went out to the battlefield even though they were wounded, and then they put their trust in Allah. Another lesson is that whoever takes Allah as sufficient, Allah brings him back with blessing, bounty and protection, as verse 174 says. That Ibrahim (peace be upon him) and Muhammad ﷺ said the very same words shows that the path of the prophets is one.
When and how to say it
When a person faces fear, an enemy's threat or a hardship beyond his power, saying «Hasbunallahu wa ni'mal wakil» or «Hasbiyallahu wa ni'mal wakil» with conviction in the heart is the way of the prophets. In Sunan Abi Dawud there is a narration that says: first make a sensible effort, and when the matter overpowers you, say these words. The hadith scholars differ about its chain, though its meaning agrees with the teaching of Tawakkul. There is no authentic hadith for reciting these words a specific number of times, such as hundreds or thousands of times, or in the form of a fixed wird (daily recitation). The words themselves are very great, but the fixed counts are man-made.