The duo will not travel with the rest of the squad for Wednesday's closing Group E clash in Moscow.
Costa was influential off the bench as late goals from Philippe Coutinho and Neymar downed Costa Rica on Friday.
But the Juventus winger will not be available for the Serbia match as he has a hamstring injury, team doctor Rodrigo Lasmar confirmed.
"At the end of yesterday's game, Douglas Costa complained of pain in his right hamstring," Lasmar told reporters. "Just remember he arrived injured, but in the left leg. That is different from this complaint.
"He was diagnosed with a minor muscle injury so he will not travel with us. He will stay in Sochi, where we have a structure suitable for him to recover as soon as possible.
"We'll have a physiotherapist here. He will continue the recovery process here, along with Danilo, who will not travel and will have physiotherapy aimed at recovery.
"We are optimistic about his participation in the competition, depending on our performance at the World Cup. We are sparing no effort so can he still help us.
"The case that is most worrying is Douglas Costa's, but Danilo's is not much different, except that his is a less important, secondary muscle, so there's a little better expectation with respect to him."
Lasmar, though, is not willing to speculate on when Costa may be ready to return to action, with Brazil needing a point against Serbia to guarantee a last-16 spot.
"We are not going to need a date when he will be ready," Costa said.
"It is clear he is not in condition for this game and his recovery will tell us. We are imagining within a favourable time in the competition."