Fentanyl is a pain medication. It is used in combination with a benzodiazepine such as Midazolam for conscious (moderate) sedation in procedures where general anesthesia or deep sedation is unnecessary. It can also be used as a continuous IV drip for people who are intubated and sedated using other meds, propofol, dexmedetomodine, ketamine. If the coughing you are talking about is from an endotracheal tube, then Fentanyl does nothing to combat that. When people are intubated for surgery, they are given a paralytic so they don't fight the tube being placed. Usually succinylcholine, vecuronium, or rocuronium depending on the length of procedure. Gas is also used in general anesthesia, sevoflurane, isoflurane, desflurane.
Fentanyl is a great medication for pain when used correctly. It has a quick onset and short half life so it works quickly and gets metabolized fairly quickly depending on the patient's liver status.