How is this possible?
Let's look more closely at your linked verses:
5 God called the light “day,” and the darkness he called “night.” And there was evening, and there was morning—the first day. (Genesis 1:5)
This verse implies the creation of light and the implementation of it to create the first day. Darkness already existed, so only light was needed.
16 God made two great lights—the greater light to govern the day and the lesser light to govern the night.
This verse implies the creation of the sun and moon—notice the "greater" and "lesser" lights.
These lights—the sun and the moon, which were created three days after light itself was—are simply vessels to carry greater and lesser versions of the previously created light which govern the limits of the day and of the night.
And if we read a bit further:
16 cont. He also made the stars. 17 God set them in the vault of the sky to give light on the earth, 18 to govern the day and the night, and to separate light from darkness. And God saw that it was good.
Stars were created to be vessels for light as well, but to separate this greater light (the sun) from this lesser light (the moon), and to govern both day and night.
Before questioning the bible (and God, by extension), always look more closely at what is being said and you will understand. This is especially true for scripture, because many times we find it to be ambiguous, but upon closer examination it just comes to us.
The key to this question is to recognize the point of view from which the story is being told. The point of view is established in Genesis 1:2:
Now the earth was formless and empty, darkness was over the surface of the deep, and the Spirit of God was hovering over the waters.
If we read the rest of the account from the point of view of "hovering over the waters," the order of creation makes perfect sense, according to a modern scientific understanding of the formation of planets:
Day 0 -- Formless void
As the Earth condensed out of the primordial disk, it appeared just as the Genesis writer says, "formless and void."1
Day 1 -- Light
The atmosphere of the Earth thinned and changed to the point that light from the sun could penetrate, and be visible from the surface of the Earth--although the atmosphere was not yet thin enough (transparent) for the sun to be seen directly.
Day 2 -- Separation of water
As the atmosphere continued to condense, water gathered "above" (clouds) and "below" (sea), leaving a "vault" (of air) between them.
Day 3 -- Dry land and first plant life.
As the planet continued to take shape, masses of dry land began to appear as distinct from the oceans. At this point it finally becomes possible for basic plant life to exist, distinct land vegetation, as well as water vegetation
Day 4 -- Sun, moon, stars
Finally, as the atmosphere continued to develop and thin, heavenly bodies--the sun, moon and stars--became visible.
1 Taken from Genesis 1: A Scientific Perspective, by Hugh Ross, Page 5.
What's written in the Bible is not necessarily intended to be used as a science textbook. While what's written is entirely true and reliable, we do have to read it in the way it was meant to be understood.
It seems sensible to me that the creation account in Genesis is not an attempt to describe in precise detail exactly how God created the universe. Rather, it is an expression of a far more important idea: God created the universe out of nothing merely by speaking it into existence. As finite beings, we are not likely to fully understand the mind of God or the full complexity of his creation, and so it's entirely likely that what is expressed in Genesis is simplified so that we can understand some important feature(s) of the underlying facts. In that sense, I think it's possible to read precision into what is written. The thrust of this idea is that we should understand that we should have a healthy amount of skepticism of the quality of our own understanding of something (presumably) very, very complex, and that we should focus on the ideas we think God is trying to get across to us.
That aside, it seems entirely plausible that in the early portion of creation, natural laws had not yet all been implemented. We're told next to nothing about such things directly. If you don't create the entire universe simultaneously, then it makes some sense to me that portions of it would not function the same way as they do now and that not until it was completed should we assume that it would closely resemble the universe we observe today (regarding physical laws, in this case). I see no reason why certain natural laws could not be circumvented or ignored by the Creator during this process. Speaking things into existence is not something I think I can grasp at a scientific level because I have no such power to recreate that phenomenon, nor can I observe it happening (to my knowledge).
Rather than read contradiction into the details of the creation account in Genesis, I think it makes much more plain sense to accept it for what it does say (because it's not incorrect) and attempt to answer those questions that the ultimate author of text intends to address.
I don't know how light can exist without a source, but then again, I don't know how you could create light out of nothing. God's power to accomplish all these things is quite beyond me.
I don't fault you for wondering how God accomplished all that he did, and I think it's possible to find an answer. I'm just not convinced that Genesis 1-2 is an attempt to provide a detailed answer to that question.
It is unfortunate that this concept is often used to make the Bible seem to contradict itself.
However, contrary to popular belief, the Bible doesn't waste words.
The fact that God tells us how many days, also gives us time periods; in other words, God began to measure time cycles (such as day and night) before the sun ever appeared.
Furthermore, there is no need to try to explain it away as "ancient philosophies". The Bible was written under inspiration of the one who created everything, therefore, it's kind of hard to argue with Him (no joke intended).
He said first, let there be light. Then according to the Bible he separated darkness from the light. This doesn't have anything to do with a sun/moon cycle, but rather with light and darkness, and time periods.
And there will no longer be any night; and they will not have need of the light of a lamp nor the light of the sun, because the Lord God will illumine them
God created light on the first day of creation. The sun is just something that produces light.
The underlying assumption of many is that the sun defines day and night, so day and night cannot exist without the sun. However, that assumption is perhaps incorrect from a biblical perspective.
If the sun is supreme, then the sun would, indeed, define day and night. However, the Bible teaches that God created day and night first. God, as Creator, is certainly powerful enough to define a "day" independent of the sun. The earth could have spun prior to their being a sun around which to orbit. We certainly aren't given enough information to know for sure, but it certainly is a possibility.
Later, the Bible indicates that God created the sun, and perhaps the revolution of earth continued, but now had hours of light and dark due to the light produced from the sun.
Again, we can't know for sure, the assumption that the earth could not have been rotating or have a definition of day and night prior to there being a sun could be invalid. Mankind has only existed after the creation of the sun, so our perspective is limited and it is perhaps difficult to envision something outside the box that we are in.
In the cosmology of the raquiyah, the dome separating the waters from the waters, it is perfectly comprehensible that the day could exist without the existence of the sun.
For us post-Enlightenment folks, it's interesting to think about our wondering and confusion about that. We have an ingrained mental model of the solar system. It's fairly clear to you and me that the sun isn't just a light in the sky, but it's the source of the energy that warms the earth and makes the atmosphere glow blue.
So, for you and me to wonder about the Genesis 1 cosmology, and how it could be so, is to get in touch with our ancestors who wondered how it could be so. Watch the film The Truman Show to get a sense of what this dome cosmology might have been like.
There's another cosmological model besides the dome in the Bible: the circles-of-heaven model of antiquity. St. Paul talks about ascending to the "third heaven." That's part of a cosmological model that puts God in the seventh heaven. We have echos of that model in the hymn verse "immortal, invisible God only wise, with light inaccessible hid from our eyes."
For a biblical take on all this that reminds us of our contingent and limited human perspective, I strongly recommend that you read Job Chapter 38. Any translation will do. http://bible.oremus.org/?passage=Job+38