光 is only used in colloquial situations, whereas 只 can be used both in colloquial and formal situations. However, in one phrase 光 cannot be replaced by 只, namely 光是……就…… E.g. 光是这一顿饭就花了他三万块钱。 In this phrase, it is more natural, personally speaking, to replace 光 with 仅仅.