'A' and 'an' function as the indefinite forms of the grammatical article in the English language and can also represent the number one. An is the older form (related to one, cognate to German ein; etc), now used before words starting with a vowel sound, regardless of whether the word begins with a vowel letter. Examples: a light-water reactor; an LWR; a sanitary sewer overflow; an SSO; a HEPA filter (because HEPA is pronounced as a word rather than as letters); a hypothesis; an hour; a ewe; a hero; a one-armed bandit; an heir; a unicorn.
Merriam-Webster's Dictionary of English Usage is more descriptive than prescriptive, but it advises, "You choose the article that suits your own pronunciation." Theodore Bernstein gives the straight vowel-sound vs. consonant-sound explanation but allows that one should indeed say "an hotel" if they think hotel is pronounced otel.
An analogous distinction to that of "a" and "an" was once present for possessive determiners as well. For example, "my" and "thy" became "mine" and "thine" before a vowel, as in "mine eyes". This usage is now obsolete.
The appearance of an or a in front of words beginning with h is not limited to stress. Sometimes there are historical roots as well. Words that may have had a route into English via French (where all h's are unpronounced) may have an to avoid an unusual pronunciation. Words that derived from German however would use a as the h's would be pronounced. There is even some suggestion that fashion may have had some influence. When England was ruled by a French aristocracy, the tradition may have been to exclusively use an, while when Britain was governed by a German-based monarchy the tide may have changed to a.
Further, some words starting with vowels may have a preceding a because they are pronounced as if beginning with an initial consonant. "Ewe" and "user" have a preceding a because they are pronounced with an initial y consonant sound. "One-armed bandit" also has a preceding a because it is pronounced with an initial w consonant sound.
To add emphasis to a noun, the preceding indefinite article is often pronounced as a long a (just as the definite article would be pronounced as "thee" in such cases), whether or not the schwa, or even "an" would be the appropriate usage. In recent years, there has been a noticeable trend to pronouncing almost all indefinite articles in this way, especially in radio or television announcements or news-reading.
A and an are also used to express a proportional relationship, such as "a dollar a day" or "$150 an ounce" or "A Mars a day helps you work, rest and play", although historically this use of "a" and "an" does not come from the same word as the articles.
The mathematically-minded might heed H. S. Wall's reminder that the statement "I have a son" does not necessarily imply that "I have exactly one son" or that "I have only sons". In other words, "The little words count." — H. S. Wall, Creative Mathematics.