How was the Kaguya clan related to Kaguya and when was the clan formed?
The when and how the clan came to be are fairly unclear through out the series. But we can make a guess as to when very roughly.
According to this timeline, Gamamaru was born in 984 BK (before nine tails attack). Which was said to be the same generation as Hagoromo, the first son of Otsuki. Meaning that the creation would be in one of the years to follow
This derivative power was obtained through descendants of Kaguya Otsutsuki, indirectly making Otsutsuki the creator of the Kaguya clan.
How was the Kaguya clan related to Kaguya?
By Kaguya clan, I'm guessing that you're referring to the one mentioned in this link. Well, they were descendents of Kaguya, which is why some of them gain the rare kekkei genkai "Shikotsumyaku", which gives you some of Kaguya's "bone powers". If you remember Kimimaro manipulating his bones when fighting against Naruto, you know what I mean.
When was the clan formed?
Well, we're not sure, since it wasn't mentioned in the anime or manga. But we do know that they were descendants of Kaguya, so maybe they existed a long time ago, maybe even not far after Ashura and Indra's death (unless they came from Hamura's lineage). We also know that they were extinct after their attack against Kirigakure and Kimiaro's terminal illness, but that's about it.
We know that neither Hagoromo nor Indra or Ashura used the bone Kekkei Genkai, so it might have gone to Hamura's children. Hagoromo's eyes went to Indra and his chakra went to Ashura. Hamura's eyes went to the progenitor of the Hyuuga clan. Maybe Hamura's chakra manifested in the Kaguya-clan as bone-manipulation. This hypothesis is bolstered by how Hamura was closer to Kaguya than Hagoromo, so maybe he gave one of his children the name.