How can we tell when egy is used as 'one' and when it's used as 'the'
'Egy' means 'a(n)', not 'the'
You will know when 'egy' is used as 'one' and when as 'a(n)' from context, and in some cases intonation (in speach).
And anyway, it clearly implies the amount to be one. The difference isn't huge, it's just a matter of emphasis really. (just like in German or Romanian)
Why 'egy' and not 'a'/'az'?
'Egy' is an indefinite article, 'az' is a definite article, similar to 'a(n)' and 'the' in English.