A church is a sacred place. i.e., a place designated for divine worship, and it is made so by either dedication or blessing (c. 1205).
Canon 1212 provides that sacred places lose their dedication or blessing if they suffer major destruction or if they have been permanently given over to profane uses, de facto or through a decree of the competent ordinary. Here “profane” just means not sacred.
The diocesan bishop must hear (i.e., consult) the presbyteral council, and then he can relegate the church to profane but not sordid use, according to the conditions in canon 1222. The conditions can be viewed by looking up that canon, and that can be easily done on the internet. He effects this through a decree that says the building is no longer designated for sacred worship, and that it is no longer blessed or dedicated.
The altar does not automatically loose its status by this action though. An additional decree would be needed to “remove” the blessing or dedication (c. 1238).
The Blessed Sacrament is removed, and the items for sacred worship are generally removed (such as chalices, tabernacle, etc) and stored. The items are often sent for use in poorer parishes or the mission Churches.
Keep in mind that this does not affect the existence of the parish to which the church building might belong. A parish is a community rather than a place, and It is only for the diocesan bishop to erect, suppress or alter parishes. He is neither to erect, suppress nor alter notably parishes, unless he has heard the presbyteral council (c. 515 §2). That would be an entirely separate question.
As to the initial question, the rites for dedication of a church and altar were revised in 1977. They are somewhat simpler than the former rites last updated in the Roman Missal in 1962, and there are separate rites for the laying of the foundation stone (which is blessed with holy water and just laid by the mason) or beginning work on the building.
At the dedication (and the other rites above) there is liberal use of holy water and incense, and various symbolic handing over of keys, or legal documents of ownership .
The walls and altar are anointed. If there are relics for the altar, they are sealed by a mason.