There are a number of issues discussed in this post.
Excommunication is not incurred for attempted but invalid marriage
First of all, a priest who attempts to marry does not incur a latae sententiae (automatic) excommunication. Canon Law gives a very precise list of which crimes incur this penalty, and attempted marriage is not one of them.
On the other hand, as Canon 1087 says, those who have received the sacrament of Holy Orders are impeded from contracting marriage (unless, of course, they are given an indult after laicization).
Moreover, a priest in that situation can (and eventually should) be formally warned and punished, if necessary, with gradually increasing censures, up to laicization (Can. 1394). However, generally excommunication is not one of that censures contemplated, unless there are aggravating circumstances (e.g., abortion, attempted absolution of the priest’s accomplice).
Hence, bishops, priests, and deacons who attempt a marriage after their ordinations, and persist in it, would be barred from receiving Communion, based on Canon 915:
Those who have been excommunicated or interdicted after the imposition or declaration of the penalty* and others obstinately persevering in manifest grave sin** are not to be admitted to holy communion.
So, to answer the O.P.’s questions:
- There is no excommunication to lift.
- The marriage is not recognized (unless we are talking about clergy who have already been laicized and received an indult to marry). In order for that person’s situation to become regular, he must either leave the invalid union or obtain an indult for laicization and marriage.
- Once he has done that, he may simply go to confession and return to full Communion.
- Returning to active ministry is a delicate issue that the priest will discuss with his bishop. In the case of a priest who has attempted marriage, although he is not excommunicated, he is automatically barred from exercising ministry (i.e., suspended; see Can. 1394). His bishop, or the Holy See, would have to lift the suspension before he could return to active ministry. A priest who has, for instance, fathered children will probably be counselled to seek laicization and help raise the children. On the other hand, a priest who repents and is otherwise free of obligations may very will be admitted back into active ministry. Although it incurs a suspension, a civil marriage is not completely determining, because in this case the civil marriage, although binding in the civil law, is, in fact, only an invalid attempted marriage.
Deacons and celibacy
First, some definitions: celibacy means not contracting marriage. Continence means not engaging in sexual intercourse.
All clergy without exception, as the O.P. points out, are called to celibacy. That means that, once they are ordained, they are never to contract marriage in the future. (In particular crisis cases, the Holy See can give an indult dispensing with this prohibition; however, the interested party must first seek laicization—that is, cease exercising his ministry.)
Nevertheless, deacons (and priests in the Eastern churches—as well as in some rare cases in the Western church), but not bishops, may be chosen from among married men. Like all married men, married deacons and priests are not required to live in continence.
However, unmarried clergy (like all unmarried men) must live in continence. The difference, of course, is that unmarried clergy must remain continent for life, whereas unmarried laymen may, of course, marry.
Again, to answer the O.P.’s questions: married priests and deacons do not have to abstain from the sexual act with their wives.
What to do in case of a latae sententiae excommunication
Someone who finds that he has incurred a latae sententiae excommunication (or interdict, which is a lesser censure) should simply go to confession and ask for advice from the priest.
Generally, absolution from a latae sententiae excommunication is reserved either to the bishop or, in more serious cases, to the Holy See. In some cases, the bishop (or the Holy See) delegates the faculty to absolve certain censures to his priests.
If he has the faculties, the confessor will absolve the penitent directly. Otherwise, he will probably instruct the penitent to come back, or otherwise get it touch with him, after a certain amount of time (a couple of weeks or so), so that the priest has time to make recourse (as the case may be) to the bishop or to the Holy See. If the penitent prefers, he can make that recourse himself, although it is preferable to go through the confessor in order to protect the penitent’s identity.
A “shortcut” is to go a so-called “minor penitentiary”—a priest designated by the bishop, or by the Holy See, who can absolve from censures. Every diocese should have them at the cathedral, and there are some at all of the four major Papal basilicas in Rome (St. Peters, St. John Lateran, St. Paul Outside the Walls, and St. Mary Major).
*Again, for clergy to attempt marriage does not incur an excommunication. In any case, Canon 915 does not apply to latae sententiae excommunications that have not been publicly declared.
**Nevertheless, persisting in an invalid marriage without regularizing it is a case of so-called manifest grave sin.