(CNN) Flanked by Iraqi forces of all stripes, Prime Minister Haider al-Abadi declared Mosul has been recaptured from ISIS.

"From here, from the heart of the liberated and free Mosul, by the sacrifices of the Iraqis from all the provinces, we declare the great victory for all of Iraq and Iraqis," al-Abadi announced Monday.

"This is a great celebration that crowned the victories of the fighters and the Iraqis over the last three years."

The US-led coalition fighting ISIS, Combined Joint Task Force Operation Inherent Resolve , congratulated Iraqi security forces "on their remarkable progress against ISIS while making extraordinary efforts to safeguard civilian lives."

The victory marks an end to a nine-month operation, which began when fighters of different ethnic and religious backgrounds made a coordinated push toward the city as US-led airstrikes helped pave their way.

Iraqi forces planted a national flag on the banks of the Tigris River in Mosul's Old City to declare their victory, although fighting was still underway in one small pocket of the city Monday morning.

The victory marks the beginning of a long, arduous road to rebuilding the metropolis. Much of the historic city is reduced to rubble and is still under threat of ISIS attacks.

Soon, Iraqi officials and Mosul residents -- as well as their US allies -- will need to start looking at a long and challenging to-do list.

Rebuilding a city torn to shreds

CNN journalists in Mosul's historic Old City saw a place almost entirely reduced to rubble on Monday.

Very few civilians remain in the area -- there is simply nowhere for them to live -- but some were seen trying to return, even visiting the ruins of the Al-Nuri Mosque, which was blown up by ISIS last month

JUST WATCHED Mosul's Great Mosque of al-Nuri blown up Replay More Videos ... MUST WATCH Mosul's Great Mosque of al-Nuri blown up 02:22

Fawaz Gerges, a Middle East expert at the London School of Economics and Political Science, said that there was no time to waste in beginning social and physical reconstruction.

"The first challenge facing the Iraqi government and international organizations is to provide basic necessities of life for more than 400,000 Iraqis who have been displaced from the western part of Mosul, which mostly lies in ruins," Gerges told CNN.

He estimated that rebuilding the Old City alone would cost $1 billion.

In some parts of Mosul, residents have begun to return from displacement camps to think about rebuilding. CNN drove through some of these areas, and saw signs of life returning to normal -- traffic on the roads and chickens being sold in makeshift markets.

Some people have left their villages for safer ones -- like Taysir Mohammed Mahmoud, a former restaurant owner who left the Old City for the safer east with his wife, two children, brother and mother.

He and his family had been used as human shields by militants and were forced to move to another place, where they lived with 10 other families in a basement for five months, he told the UN refugee agency.

"Thank God we are here. We'll celebrate our new birth," says Mahmoud, who lost his home in the fighting.

"But we will need help ... help to go back, rebuild and get back to work."

Holding ground and security

In the push toward Mosul, forces retook dozens of villages in their path from ISIS fighters. In many cases, the militants simply fled and returned when security forces had moved on. In some cases, they came back to carry out mass executions of civilians.

Iraq and its allies will have to work on creating a strong and permanent security presence in Mosul to ensure this does not happen.

JUST WATCHED Iraq declares end of ISIS control in Mosul Replay More Videos ... MUST WATCH Iraq declares end of ISIS control in Mosul 02:57

"We all know that ISIS hides among civilian populations and ISIS will be counting on sympathies among certain individuals in the civilian population to operate an insurgency," said Lina Khatib, head of the Middle East and North Africa Program at Chatham House in London.

"So it is very important for Iraqi officials to gain the trust of the civilian population to make sure this doesn't happen."

The US has been heavily criticized for leaving Iraq in a weakened position after its invasion in 2003 and ensuing war. Some critics say that US actions aimed at eradicating al Qaeda in Iraq created the vacuum for ISIS to gain a foothold in the country -- Mosul was the militant group's largest city and its crown jewel.

US officials are aware of the risk of history repeating. They are engaging more with tribal leaders to make sure they have the local buy-in to make sure a new incarnation of ISIS does not find a space in Mosul again.

Iraqi forces celebrate the retaking of Mosul on Sunday.

Gerges warned that the US must learn lessons from the Iraq war.

"To the Trump administration, one warning is in order: Defeating ISIS militarily is not enough. Al Qaeda in Iraq was defeated between 2007 and 2010, yet it made a spectacular return," Gerges said to CNN.

The US said last winter that it was helping to train some 15,000 members of a Sunni Iraqi tribal militia to hold the city, but some Iraqi officials have told CNN that they didn't think there had been much progress so far. It's unclear whether that force is ready to be fully deployed.

Parts of eastern Mosul that have been retaken from ISIS are not exactly peaceful. While ISIS has lost its control there, attacks continue and terror-related arrests are still being made.

It is the same story in other areas captured from ISIS. The town of Fallujah was retaken in the summer of 2016, but nine months later the mayor had still not returned to live there because of the insecure situation.

Working out who's going to rule

Perhaps one of the biggest challenges on the to-do list is to work out who will be in charge of what.

Talks on who is going to rule Mosul are on the front burner, but a source close to the issue told CNN that essentially nothing had yet been agreed on how the city should be run.

A commission established to discuss these issues has never met, the source said, nor is there an agreement on any form of power sharing among the many groups in Nineveh province.

JUST WATCHED Can ISIS ever be eradicated? Replay More Videos ... MUST WATCH Can ISIS ever be eradicated? 01:34

US and Iraqi officials have spoken of creating eight self-governing areas in and around Mosul. Ever since Iraq's new constitution was passed, there's been much talk of local autonomy, but it's rarely been delivered.

Mosul is made up of a diverse group of people with different ethnic and religious backgrounds -- including Sunni and Shia Muslims, Christians, Kurds and Yazidis -- and in the past, the lack of Sunni Muslims in governance has been a source of tension and conflict. ISIS was able to play on this issue and find sympathy among Sunni Muslims in Mosul.

But al-Abadi has tried hard to brand the fight against ISIS as a national one, involving a range of ethno-religious groups fighting under one national Iraqi flag.

Nonetheless, the extensive role of the Popular Mobilization Units -- which are made up of predominantly Shia groups -- in the ISIS fight hasn't gone unnoticed among Sunnis.