Though popular typology adopts Zoroastrian theology where light and darkness are good and evil, if we let scripture speak for itself, another picture emerges.
Gen 1:1 bereshit bara elohim...
The word 'bara' means 'create'. Playing with puns as Matthew did, 'bar' as son is in 'bara'.
Bar Elohim is the Son of God.
In the verses following Gen 1:1 whenever god creates he speaks his creation into existence. Therefore the rabbis say that 'bara' is the word which creates. You won't find it in a Hebrew dictionary, but you will find various rabbis use it in such a manner. We will just say "Word".
When John wrote his gospel, he began with Gen 1:1 (not Greek philosophers as some surmise).
Bereshit means 'the begininng'. In bereshit is the word bara. Vowels didn't exist in the original, so don't let vowel shifting bother you. John could say, "in the beginning was the Word".
Bara is next to the word elohim, so John could say, "The Word was with God".
Bara describes God as the creator, so John could say, "The Word was God".
Elohim has a pun "l'chaim" meaning life, so John could say "In him was life".
Elohim has another pun "alo khoom" meaning 'not dark', so John could say, "and the life was the light of men."
The Light was self-existent as Elohim, and yet it was created when God said, "Let there be light". This is a riddle. We know that Christ is the Light. So the riddle is easy. He was God, and yet he was a created man in the flesh. Please don't assume I am talking about anything other than fundamental theology of Christ being both man and God.
John attributes the condemnation of man to the Light, while at the same time saying that Christ did not come to condemn:
Joh 3:17 For God sent not his Son into the world to condemn the world;
but that the world through him might be saved.
Joh 3:19 And this is the condemnation, that light is come into the
Riddles are intended to make us consider details of what is being said. Jesus was sent to save us. However, he faced the same temptations as we do, but he did not sin, thereby removing all our excuses to sin, and putting us to shame. His perfect life required for him to be the lamb without blemish, is the final judgement of man.
So Light represents Jesus's holiness, the holiness of God, which puts us to shame.
and men loved darkness rather than light, because their deeds were
This is an ambiguous statement. It does not say that darkness is evil. It says that evil men love darkness. Considering that I am an evil man, I love the grace of God and I hide my sin in it. The opposite of holiness is not evil, it is grace.
Holiness condemns us, and grace gives us life.
The fact that there was darkness before creation does not mean that there was evil. It means that God existed in grace/love. The darkness implies that God is more than one person because love cannot exist unless there is someone outside of yourself to consider first.
But the light, though it existed hidden in Elohim could not be expressed because with holiness comes separation. There was no separation between the members of the Trinity. Only after creation could holiness be expressed as God being separate from his creation.
The two trees in the garden fully expressed the holiness of God and the grace of God. The tree of life was fully accessible, and the tree of death was set apart for God's purpose. Man was not to eat of the fruit. Eating the fruit violated God's holiness which required a greater separation in penalty and training.
Man has lived in darkness or grace since the fall. It is only because of grace that it hasn't all been destroyed. As we come to Christ we are to walk in the light. "Go and sin no more' "Be ye therefore Holy" declares the Lord.
With that background, the question can be addressed:
How does God form light?
In Isaiah 45:7 (ESV):
I form light and create darkness, I make well-being and create
calamity, I am the LORD, who does all these things.
Ge 2:7 And the LORD God formed man [of] the dust of the ground, and
breathed into his nostrils the breath of life; and man became a living
Gen 2:7 is a picture of the incarnation of Christ. Since the physical life of Christ is the light, God formed the light of the world.
How does God 'create grace'
Man was created in God's image and likeness. As such we have been commanded to forgive as He forgives. He has created grace in and through us.
The phase "I form light and create darkness" can be understood as a parallel passage to "Let us make man in our image and likeness..." Christ was made in the image of God, and his bride was made to be 'like' him.
How does God create calamity
Rom 1:18 ff tells us that God is angry because men do not acknowledge him as God, nor give Him thanks. He has created the algorithms of life such that when He gives you what you want... the freedom to choose your own path, you also get to wallow in the consequences brought upon you by his system. Sin causes calamity because God created a system where choices have consequences.
When we sin, it is like jumping up and down in a swimming pool, as the ripples of destruction caused by our sin spread out across the pool. The consequences of my sin collide with the consequences of your sin and with those of everyone else. Sometimes I receive calamity and I can trace it back to my particular sin. Sometimes I can trace calamity to your sin. And sometimes I get hit upside the head with calamity and it is the perfect storm of waves which are untraceable to anyone in particular. But all calamity as a result of sin can be claimed by God, since he created the system whereby our jumping up and down causes waves.