Generally, foreigners from the EU, USA, UK, Canada, South Korea, Poland and some other countries have the right to stay in the territory of Ukraine legally under the visa-waiver regime (within 90 calendar days during the last 180 days). About non-visa countries you can read by this link. If foreigners are nationals of countries with which Ukraine has a visa regime, may temporarily stay in Ukraine on a visa basis. See the list of countries which citizens are required to obtain a visa to enter Ukraine here.
The procedure of calculating 90 days of stay under the visa-waiver regime in Ukraine is carried out according to the relevant rules. You can read about it here.
So, how to extend your staying in Ukraine for more than 90 days?
Of course, you must obtain a temporary residency permit (permission) in Ukraine.
A temporary residence permit entitles a foreigner to reside legally in Ukraine with the right to extend such a temporary residence permit in Ukraine.
Temporary residency permit is the official document, that gives the right to its holder to legally stay in Ukraine, leave and reenter the territory of Ukraine an unlimited number of times within the term of validity.
Temporary residence permits` validity term may be: from several months up to several years (for example, in case of the work permits 3-year validity or long-lasting international project etc.).
The law of Ukraine establishes the following list of grounds for getting temporary residence permit:
• Official employment;
• Participation in international projects for technical support (such programs should be registered);
• Performance of religious activity or invitation by a religious organization (officially registered and with permission to involve foreigners);
• Employees of affiliated companies or representative offices of non-governmental organizations of foreign countries, registered in accordance with the legally prescribed procedure in Ukraine;
• Employees of representative offices of foreign business entities, banks;
• Participants of international cultural, educational or scientific activities, prescribed in international contracts of Ukraine or specific programs, participants of international or regional volunteer programs, or participation in work of Ukrainian organizations that are permitted to involve foreign volunteers (there is a special governmentally approved list of such organizations);
• Education in Ukraine (it must be already arranged, not just an intent)
• Investing at least 100 000 EUR in Ukrainian business;
• Marriage with the citizen of Ukraine.
Moreover, before applying for temporary residence permit the applicant will have to get type D visa (read more about visas to Ukraine).