What is the difference between using 光 vs using 只? What is the gramatical difference between 光 and 只?

光剩下2毛钱 does not have the same meaning/context as 只剩下2毛钱

It seems there is more emphasis to the part that comes after 光. When is the right time to use one over the other.
只 is more limited in grammatical scope: it can only function as an adverb, preceding the verb. 光 has a larger range of related uses, from being a pre-verbal adverb (also called a restrictive adverb) like 只, to a resultative complement used when a verb 'finishes' an associated noun (e.g. in 吃光了), as well its adjectival/adverbial meaning of 'empty' and 'naked'. 光 can also precede nouns and other adverbs (e.g. of time) in the sense of "only" where 只 cannot. However, words that include 只 such as 只要、只是 are used in a greater variety of set constructions (among the most well-known being 只要 X 才 Y).

However, both 只 and 光 can be used as pre-verbal (restrictive) adverbs, as the famous "只/光剩下2毛钱" sentence illustrates. There have been various analyses: 光 being more colloquial and characteristic of the spoken language, while 只 is preferred in the standard written language but is itself neutral with respect to spoken vs written. This is perhaps the most basic distinction in their use as adverbs: see Baidu's explanation. It is also known that 只 adopted its meaning of "only" earlier on (at the latest from the late Han dynasty) whilst 光 in this meaning is not even attested in the Kangxi dictionary (see zdic.net).

There is a claim that a clause with 光 implies a negative clause further on. One further explanation found on that website is that 光 with 有 has a focus on things other than the object of 光有, whilst 只有 shifts the focus onto the object of the clause itself. It uses the example 只/光有口号，是没用的 to make this point.

There is also the idea that 只 with quantitative measures (such as in the 2毛钱) means limited to that quantity, whilst 光 focuses on the object and the fact that it is alone. The modified sentence 口袋里只/光剩下2毛钱 illustrates this potential distinction: 只 may allow the possibilities of other non-money items in the pocket, whilst 光 emphasises that this money is all that exists in the pocket. 

For some of these later points, there really aren't many trustworthy sources. It may be an interesting point on which to do some further research! There are also a few other words for "only", such as 单 and 仅 which could be examined.