How did the US get the necessary knowledge to maintain their MiGs?
Its a combination of those. US did have manuals for quite a few of the Migs- Cold war alliances were shifting too frequently to prevent any leak of military technology. As warisboring.com notes:

Because Baghdad re-established its cooperation with London and the United States in late 1963, U.S. intelligence services not only received the opportunity to test-fly MiGs in Iraq, but also received all the related technical and training documentation.


The title page of the English translation of the tactical manual for MiG-21F-13 and MiG-21PF, as prepared by the USAF’s Foreign Technology Division. Notable is the date of issue — Nov. 5, 1965 — meaning that the original document must have been obtained much earlier. Tom Cooper Collection photo; Image from warisboring.com
As the Mig program was established in late 70's US would have had the required documentation for quite a few of the aircraft before that. The rest were done during the project using inputs from US intelligence and pilots themselves writing the flight manuals.
The Soviets sold their aircraft to many countries, the manuals for which could've been obtained from any of them. Also, there are multiple instances of pilot defection with manuals, which provided most of the required technical data for flying, though maintenance would have been difficult. As airforcemag notes:

This led to the second maintenance problem—the lack of instruction manuals  and  tech  data.  US  intelligence supplied  some  of  the  information they  needed  but  not  nearly  enough ...
Parts  were  their  third,  and  maybe biggest, problem. “For things like hydraulic pumps, we would use American components that looked about right,” said Stringer. “But it was only about five to 10 percent replacement. Most of the time we tried to recondition.”