the literal meaning of these two words are pretty much the same but differ according to the context and concept in which it is used. as you have mentioned these terms can be mainly found in literature related to sufism and also in hadith as well as islamic jurisprudence. but the meaning derived in each usage has a slight difference while the main theme remains the same.
before we look into the usage it is wise to have a basic foundation of understanding of the literal meaning of these two terms/words.
khalwa in english is generally defined as solitude/seclusion whereas uzla is generally used in the definition of loneliness/isolation. there are variations of meaning in these terms when used in different contexts. if you look at the sufi literature you can see they have an exageratted meaning of these terms in comparison to hadith and islamic jurisprudence literature.
as you have asked this question with main relevance to understanding it with the context and concepts you have mentioned, i do not find its relevant to mention the usage and appearance of these (solitude & isolation) in the quran. but just to have more clarity you can refer to the verses about what is said about the people of the cave (surah 18), hajar (surah 2 & 14), yousuf (surah 12), younus (surah 37) and also maryam (surah 19).
there are authentic reports and narrations about our beloved prophet PBUH isolating himself to worship Allah Azzawajjal. thus the understanding of the term should be derived from the ways/actions of prophet PBUH.
khalwa (seclusion) means to isolate oneself to worship Allah and this has to be practiced just as how prophet PBUH and his companions did. the main concern i see is that the some misunderstand the concept of uzla and mix it with the afore-mentioned practice of khalwa, thus creating an exaggerated form.
one example of this is when some practice khalwa, they avoid/miss or rather do not try to attend the congregation prayers at the mosque. and once this was attributed to sheikh abdulqaadir jilaani. but it is clearly written in his book, Sirrul Asraar:
You may be in seclusion while fasting, but you MUST PRAY WITH CONGREGATION IN THE MOSQUE AT ITS TIME.
thus exaggeration and misunderstanding has made some deviate to such extent. creating unnecessary differences which actually should not be there.
uzla (isolation) is preferred in cases where a Muslim fear for his religious commitment because of widespread tribulation. this is different from the context of khalwa but having similarities in concept, as both involves removing oneself.
as narrated in bukhari (7088) & muslim (1888), ibn hajar said in fath al-bari (13/42) :
This report indicates that isolation is preferable in the case of one who fears for his religious commitment.
and Al-Sindi said in his foot notes on al-Nasaa'i (8/124) :
This shows that it is permissible to isolate oneself, indeed it is preferable at times of tribulation.
so as you have mentioned in your question, uzla is also kind of isolation for worship. (here we take the broadest meaning of worship, as everything we do that pleases our Rabb is defined as worship) it differs from khalwa because uzla is to be adopted when one has reached to the state which it becomes relevant, whereas khalwa at its authentic way, is recommended to practice often.
as differences are slight and similar, its the application of the terms what really differs. as these two terms are arabic words, they are bound to appear in hadith literature as well as in other. but it does not mean that they carry the same and exact meaning when used separately. specially in literature related to sufism the meanings are presented in a bit more aggressive way, in accordance with their thought of teachings.
what we have to understand is that it's always better not to isolate/seclude oneself to such an extent when there is no fear of any great tribulation for one's deen.
- The believer who mixes with people and patiently bears their annoyance will have a greater reward than the believer who does not mix with people and patiently bears their annoyance. (Classed as saheeh by al-Albaani in Saheeh al-Tirmidhi, 2035)
for further understanding, i would like to mention one more narration that i believe is relevant to the whole concept of understanding this isolation & seclusion, insha Allah.
- Ibn Umar reported: The Prophet, peace and blessings be upon him, prohibited isolation, that a man spend the night alone or travel alone. (Musnad Ahmad 5618)
for more clarity on this hadith, we can find in fath al-bari (2693) ;
Al-Tabari said, "This is discouragement in the form of discipline and guidance, as it is feared that one alone might succumb to loneliness and isolation, yet it is not unlawful. The lone traveler in the wilderness and likewise the lone resident in his house are not safe from succumbing to loneliness, especially if one is afflicted by bad thoughts and a weak heart."
may Allah the mighty and sublime grant us mercy and guide us to the straight path.
Allah knows best