In general terms,
Quote Quoting State Department Information
What If I Surrender My Green Card?

Generally, if you surrender your green card during the taxable year, your tax status as a resident alien will terminate on the last day of that calendar year. However, if you can establish that, for the remainder of the calendar year, your tax home is in a foreign country or you maintain a closer connection to that foreign country than to the United States, your residency termination date will be the date you surrender your green card.

If you are a resident of the United States because you meet both the substantial presence test for the taxable year and have a green card during the taxable year, your residency termination date will be the later of the date you surrender your green card or the last day you are physically present in the United States, provided you can establish one of the exceptions above. See Pub 519 (U.S. Tax Guide for Aliens) and the instructions to Form 8840 (Closer Connection Exception Statement for Aliens) for additional information.

If you are a nonresident alien as of the last day of the year and a resident alien for a portion of the year, you should file a Form 1040NR even if you have no U.S. source income and attach a copy of Form 1040 that reflects your income for the period of the year that you were a resident alien.

What if I am a Long-Term Resident When I Surrender My Green Card?

If you are a long-term resident of the United States, defined as an individual who is a U.S. lawful permanent resident in at least 8 of the prior 15 taxable years prior to the termination of permanent resident status, there are special rules to comply with. Your residency termination date will not occur until you file a completed Form 8854 with the IRS and notify the Department of Homeland Security of your termination of residency, notwithstanding that for the remainder of the taxable year your tax home is in a foreign country or you have a closer connection to a foreign country. Until you file Form 8854 with the IRS and notify the Department of Homeland Security of your termination of residency, your termination of your permanent resident status for immigration purposes will not relieve you of your obligation to file U.S. tax returns and report your worldwide income as a resident of the United States. For purposes of U.S. tax rules, the date of your termination of residency will be the later of the date you notify the Department of Homeland Security or the date Form 8854 is filed with the IRS in accordance with the instructions for the form.