The two men - an American identified as Kevin King and an Australian identified as Timothy Weekes - were abducted from the capital, Kabul, outside the American University in 2016.
President Mohammad Ashraf Ghani confirmed that the government will conditionally release Anas Haqqani from Bagram prison in exchange for the release of two lecturers of the American University of Afghanistan.
The Afghan leader added that the release of the two professors would "pave the way" for the start of unofficial direct talks between his government and the Taliban, who long have refused to negotiate with Ghani's administration.
It is thought the exchange could lead to progress in national peace talks.
In August 2016, gunmen wearing military uniforms kidnapped two professors of the American University of Afghanistan in the heart of Kabul.
"In order to pave the way for face-to-face negotiations with the Taliban, the government has chose to free Taliban prisoners in exchange for two university professors", Mr Ghani said in a televised speech.
While he did not specify the fate of the Western hostages - an Australian and an American - Ghani noted that "their health has been decorating while in the custody of the terrorists".
The pair then appeared in a video, released in January 2017, appealing to then US President-elect Donald Trump to agree to a deal to secure their release.
Taliban fighters have been battling U.S., North Atlantic Treaty Organisation and Afghan government forces since they were toppled in 2001 after their government sheltered 9/11 mastermind Osama bin Laden. Anas Haqqani has been in Afghan custody since October 2014 when US security forces nabbed him while en route to Qatar from Bahrain.
All three prisoners are members of deadly Haqqani wing of the Taliban that include Anas Haqqani, a younger brother of the group's leader, Mali Khan and Hafiz Rashid.
Media captionIs peace with the Taliban possible?