Origins of 屋根{やね}
屋根{やね} is a compound of 屋{や} "house, dwelling" + 根{ね} "root → fundament, base supporting the whole". This word is quite old, appearing already in poem 779 of the Man'yōshū, one of the oldest pieces of written Japanese dating to 759, with parts that appear to be older still.
The age of this term might point to its origins: houses in ancient Japan were dugouts, where the roof came right down to the ground:

There is more about these houses here on the relevant Japanese Wikipedia page. As such, the thing that formed the basis of a house was the roof itself: "house + basis", thus 屋根{やね}.
Origins of 天井{てんじょう}
Meanwhile, 天井{てんじょう} was borrowed out of Chinese. At its root, this is a compound of 天{てん} "heavens" + 井{じょう} "well; wellhead; wellhead shape". 井 read with the kun'yomi of い refers to a "well", as in the place where you lower a bucket to get water out of the ground. 井 read with the on'yomi of either じょう or せい can refer additionally to the 井桁{いげた}, the crossbeams at the top of the wellhead. The crossbeams themselves look a lot like the shape of the 井 kanji, which is probably where this character came from:

By extension, 井 read as じょう or せい can refer to something with this same shape -- much like what rafters or crossbeams might look like, over which the ceiling of a room would be laid: "sky → the area above one's head + wellhead crossbeams", thus 天井{てんじょう}.